TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: myloveflyer on April 01, 2020, 02:38:12 AM

Title: What to do with a list like this?
Post by: myloveflyer on April 01, 2020, 02:38:12 AM
Code: [Select]
lst1 ‘(("N" "123.123,234.234,345.345") ("W" "456.456,567.567,678.678") ("E" "789.789,890.890,900.900"))
lst2 ’ ((“1” "X1" "789.789,890.890,900.900" "123.123,234.234,345.345"  "1" "5") (”2“ "Y1" "789.789,890.890,900.900" "456.456,567.567,678.678"  "1" "3"))
========》
lst_x ‘((“1” "X1" "N" "E" "1" "5") (“2” "Y1" "W" "E" "1" "3"))
Title: Re: What to do with a list like this?
Post by: Dlanor on April 01, 2020, 04:02:34 AM
Code - Auto/Visual Lisp: [Select]
  1. ;lst1(("N" "123") ("W" "234") ("E" "345"))
  2. ;lst2 (("X1" "123" "345" “1” “5”) ("Y1" "234" "345" “1” “3”))
  3. ;========》
  4. ;lst_x(("X1" "N" "E" “1” “5”) ("Y1" "W" "E" “1” “3”))
  5.  
  6. (defun test (lst1 lst2 / lst)
  7. (setq lst1 (mapcar '(lambda (x) (reverse x)) lst1))
  8. (foreach x lst2
  9.   (setq lst (cons (mapcar '(lambda (y) (if (assoc y lst1) (cadr (assoc y lst1)) y)) x) lst))
  10. )
  11. (reverse lst)
  12. )
  13.  
  14. ;(setq lst_x (test '(("N" "123") ("W" "234") ("E" "345")) '(("X1" "123" "345" “1” “5”) ("Y1" "234" "345" “1” “3”))))
  15.  
Title: Re: What to do with a list like this?
Post by: myloveflyer on April 01, 2020, 04:11:34 AM
Code - Auto/Visual Lisp: [Select]
  1. ;lst1(("N" "123") ("W" "234") ("E" "345"))
  2. ;lst2 (("X1" "123" "345" “1” “5”) ("Y1" "234" "345" “1” “3”))
  3. ;========》
  4. ;lst_x(("X1" "N" "E" “1” “5”) ("Y1" "W" "E" “1” “3”))
  5.  
  6. (defun test (lst1 lst2 / lst)
  7. (setq lst1 (mapcar '(lambda (x) (reverse x)) lst1))
  8. (foreach x lst2
  9.   (setq lst (cons (mapcar '(lambda (y) (if (assoc y lst1) (cadr (assoc y lst1)) y)) x) lst))
  10. )
  11. (reverse lst)
  12. )
  13.  
  14. ;(setq lst_x (test '(("N" "123") ("W" "234") ("E" "345")) '(("X1" "123" "345" “1” “5”) ("Y1" "234" "345" “1” “3”))))
  15.  
Hi,Dlanor
What if lst2 has one more element!
Code: [Select]
lst1 ‘(("N" "123.123,234.234,345.345") ("W" "456.456,567.567,678.678") ("E" "789.789,890.890,900.900"))
lst2 ’ ((“1” "X1" "789.789,890.890,900.900" "123.123,234.234,345.345"  "1" "5") (”2“ "Y1" "789.789,890.890,900.900" "456.456,567.567,678.678"  "1" "3"))
========》
lst_x ‘((“1” "X1" "N" "E" "1" "5") (“2” "Y1" "W" "E" "1" "3"))
Title: Re: What to do with a list like this?
Post by: Dlanor on April 01, 2020, 04:58:53 AM
It works for me, although it returns ((“1” "X1" "E" "N" "1" "5") (”2“ "Y1" "E" "W" "1" "3")), because that was the order in lst2. Its just a substitution function.
Title: Re: What to do with a list like this?
Post by: myloveflyer on April 01, 2020, 05:32:52 AM
It works for me, although it returns ((“1” "X1" "E" "N" "1" "5") (”2“ "Y1" "E" "W" "1" "3")), because that was the order in lst2. Its just a substitution function.
Hi,Dlanor!
Wrong return ((“1” "X1" "E" "N" "1" "5") (”2“ "Y1" "E" "W" "1" "3"))
Correct return ((“1” "X1" "N" "E" "1" "5") (”2“ "Y1" "W" "E" "1" "3"))
How to sort "N" "W" "E"?
Title: Re: What to do with a list like this?
Post by: Dlanor on April 01, 2020, 08:59:33 AM
Then what are the criteria for the sort? Are the number strings coordinates? I don't understand how you arrive at the two lists, and why there are two lists.
Title: Re: What to do with a list like this?
Post by: myloveflyer on April 01, 2020, 09:42:30 AM
Dlanor,YES!
Number strings is coordinates!
Title: Re: What to do with a list like this?
Post by: Dlanor on April 01, 2020, 11:11:20 AM
Then it would be better to store the number in the list as a coordinate. It is far easier to sort using numbers/coordinates than a text representation which has to be converted back to a number.
Title: Re: What to do with a list like this?
Post by: myloveflyer on April 01, 2020, 11:57:56 AM
Then it would be better to store the number in the list as a coordinate. It is far easier to sort using numbers/coordinates than a text representation which has to be converted back to a number.
Hi!Dlanor
Listen to your suggestion, I used to sort the coordinates and then get the new list, everything went well!
Thank you very much!