Jump to content

Recommended Posts

Posted

Ok guys have a tough one for you that has been driving me nuts.

My current situation is that I need to have the following list in a particular order x2

The first order needs to be set in the (nth x (nth 0)) portion of the list. This portion of the list needs to be in alphabetical order much like it currently is in this list. (Just happen to come out that way)

 

The second ordering will happen in the (nth 1 (nth x (nth 1))) portion of the list and it needs to be in numerical order within the list of a list of a list.

Was trying all sorts of stuff and couldn’t figure it out everything from VL-sort to VL-remove the min and send back the appended value and try it again (was getting messy really quick)

 

After it is all order it will need to be saved back to it-self.

 

Current structure

(LIST(LIST)(LIST(LIST)))

Current Setup

'((("W1" 18.0 10.5 "X")
                          (("W2" 282.0)
                          ("W3" 2.0)
                          ("W6" 205.5)
                          ("W7" 78.5)))
(("W2" 300.0 12.5 "Y")
                          (("W1" 2.0)
                          ("W8" 120.0)))
(("W3" 20.0 12.5 "Y")
                          (("W1" 2.0)
                          ("W8" 120.0)))
(("W4" 98.0 68.0 "X")
                          (("W5" 62.0)
                          ("W6" 125.5)
                          ("W7" 1.5)))
(("W5" 160.0 69.5 "Y")
                          (("W4" 1.5)
                          ("W8" 63.0)))
(("W6" 223.5 12.5 "Y")
                          (("W1" 2.0)
                          ("W4" 55.5)
                          ("P2" 37.5)))
(("W7" 96.5 12.5 "Y")
                          (("W1" 2.0)
                          ("W4" 55.5)
                          ("P1" 37.5)))
(("W8" 18.0 132.5 "X")
                          (("W2" 282.0)
                          ("W3" 2.0)
                          ("W5" 142.0)))
(("P1" 68.0 50.0 "X")
                          (("W7" 28.5)))
(("P2" 225.0 50.0 "X")
                          (("W6" 1.5))))

 

Any help you guys can provide on this or point me in the right direction would be of great help.

 

Thank you in advance.

 

CadWarrior

Posted

??

 

(defun _sortAlph (lst)
 (vl-sort
   (mapcar
     (function
       (lambda (x) (cons (car x) (vl-sort (cdr x) (function (lambda (a b) (< (car a) (car b)))))))
     )
     lst
   )
   (function (lambda (a b) (< (caar a) (caar b))))
 )
)


(defun _sortNum (lst)
 (vl-sort
   (mapcar
     (function
       (lambda (x)
         (cons
           (car x)
           (vl-sort
             (cdr x)
             (function (lambda (a b) (< (distof (substr (car a) 2)) (distof (substr (car b) 2)))))
           )
         )
       )
     )
     lst
   )
   (function (lambda (a b) (< (distof (substr (caar a) 2)) (distof (substr (caar b) 2)))))
 )
)

Posted

Probably no need for distof...

 

(defun _sortNum (lst)
 (vl-sort
   (mapcar
     (function
       (lambda (x)
         (cons (car x)
               (vl-sort (cdr x)
                        (function (lambda (a b) (< (distof (substr (car a) 2)) (substr (car b) 2))))
               )
         )
       )
     )
     lst
   )
   (function (lambda (a b) (< (substr (caar a) 2) (substr (caar b) 2))))
 )
)

Posted

Thank you for the help Alanjt

Ok _sortalph works great but i think you misunderstood _sortnum which is my fault.

Please for Below for more clerity.

 

Orginal lists

((("W1" 18.0 10.5 "X")
                          (("W2" 282.0)
                          ("W3" 2.0)
                          ("W6" 205.5)
                          ("W7" 78.5)))

 

New List

 

((("W1" 18.0 10.5 "X")
                          (("W3" 2.0)
                          ("W7" 78.5)
                          ("W6" 205.5)
                          ("W2" 282.0)))

 

Hope this clears it up a bit.

Posted

This?

 

(defun _Sort ( lst )
 (mapcar
   (function
     (lambda ( item )
       (list (car item)
         (vl-sort (cadr item)
           (function
             (lambda ( a b ) (< (cadr a) (cadr b)))
           )
         )
       )
     )
   )
   lst
 )
)

Posted

?

(defun _sortNum (lst)
 (vl-sort
   (mapcar
     (function
       (lambda (x)
         (cons (car x)
               (vl-sort (cdr x)
                        (function (lambda (a b) (< (cadr a) (cadr b))))
               )
         )
       )
     )
     lst
   )
   (function (lambda (a b) (< (caar a) (caar b))))
 )
)

 

Can't test.

Posted

Thank you!!! Thank you!!! Thank you!!! Thank you!!! Thank you!!!

Thank you Alanjt for the Correct Alphabetical sorting.

and Thank you Lee Mac for the correct Numerical sorting.

 

Now if you guys could explain it to me I would be most appreciative because at this moment i cant begin to fathom how to work this. This sorting style just blows my mind away I'm use to table based programs like MySQL

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...