Jump to content

vl-sort list of dotted pairs


Happy Hobbit

Recommended Posts

This turned into quite a lengthy debate about something I didn't actually need! Interesting though.

 

pBe solved the original question in #2 for me by making me read the Autodesk Help properly this time, instead of skimming it.

 

Thanks all for answering though.

 

I somehow knew Lee & Tharwat would have a solution to the rhetorical question posed by pBe, which certainly made me think hard, but not solved by me.

 

At least I guessed right that it would involve numberp, I suppose it could be coded using stringp instead, perhaps one for another day.

 

- Harry H :)

Link to comment
Share on other sites

  • Replies 26
  • Created
  • Last Reply

Top Posters In This Topic

  • pBe

    9

  • Happy Hobbit

    7

  • Tharwat

    5

  • Lee Mac

    2

Try these lists:.....

 

Our limits were up to 9 :lol:

 

With no duplicate keys and always a mix of letters & numbers. ;)

 

Sooo busted :D Hence the NTS

Link to comment
Share on other sites

This turned into quite a lengthy debate about something I didn't actually need! Interesting though.

- Harry H :)

 

But you had to admit that it was fun... :D I hadn't had much practice with programming lately. [ Excuses.. excuses... ] :)

Link to comment
Share on other sites

I agree, writing lisp is fun, better than logic puzzles, lisp (usually) has a useful end result, although I do admit to casual lisping where I'm just experimenting/playing about

Link to comment
Share on other sites

  • 2 years later...

Could you be so kind to explain me what is A and B? Or in other words... How is the program working? I simply do not understand the logic.

 

Thanks in advance

 

S

 

*PING*

 

Easy when you know how, isn't it?

 

The variable holding my list is z

 

All I needed was:

 

(vl-sort z (function (lambda (a b) (< (car a) (car b)))))

 

Must be half asleep still :-p

 

Thank you for that pBe

Link to comment
Share on other sites

Could you be so kind to explain me what is A and B? Or in other words... How is the program working? I simply do not understand the logic.

 

Thanks in advance

 

S

It is an anonymous lambda function a and b represent the items in a list so that (car a) is the first item of the sub list and (car b) the first item of the next sub list. you can call them what you like a & b, x & y etc
Link to comment
Share on other sites

To confuse you a bit more this is a double sort working on say X & Y values. I use it to find columns of common items based on X value.

eg ((X1 Y1 text)(x3 Y3 text).... = ((X1 Y1 text)((X1 Y2 text)((X2 Y3 text)....

 

; sorts on 1st two items
(setq lst (vl-sort lst '(lambda (x y)
(cond
((= (cadr x)(cadr y))
(< (car x)(car y)))
((< (cadr x)(cadr y)))
))))

Link to comment
Share on other sites

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...