Author Topic: What to do with a list like this?  (Read 1818 times)

0 Members and 1 Guest are viewing this topic.

myloveflyer

  • Newt
  • Posts: 152
What to do with a list like this?
« 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"))
« Last Edit: April 01, 2020, 04:09:12 AM by myloveflyer »
Never give up !

Dlanor

  • Bull Frog
  • Posts: 263
Re: What to do with a list like this?
« Reply #1 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.  

myloveflyer

  • Newt
  • Posts: 152
Re: What to do with a list like this?
« Reply #2 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"))
Never give up !

Dlanor

  • Bull Frog
  • Posts: 263
Re: What to do with a list like this?
« Reply #3 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.

myloveflyer

  • Newt
  • Posts: 152
Re: What to do with a list like this?
« Reply #4 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"?
Never give up !

Dlanor

  • Bull Frog
  • Posts: 263
Re: What to do with a list like this?
« Reply #5 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.

myloveflyer

  • Newt
  • Posts: 152
Re: What to do with a list like this?
« Reply #6 on: April 01, 2020, 09:42:30 AM »
Dlanor,YES!
Number strings is coordinates!
Never give up !

Dlanor

  • Bull Frog
  • Posts: 263
Re: What to do with a list like this?
« Reply #7 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.

myloveflyer

  • Newt
  • Posts: 152
Re: What to do with a list like this?
« Reply #8 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!
Never give up !