TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: curmudgeon on March 31, 2009, 02:26:10 PM

Title: lambda
Post by: curmudgeon on March 31, 2009, 02:26:10 PM
I have
Code: [Select]
(setq lst (vl-sort lst (function (lambda (a b) (< (car a) (car b))))))which sorts a list for me, the list is of a form
Code: [Select]
(("101" "3E16F") ("102" "3E0C3") ("103" "3DFFB") ("104" "3DFD9") ("105" "3DFA8") ("106" "3DFCA")....)text content, entity handle. I guess I should call this an association list because the text is the (1 . "text") from one entity, and the other is the (5. "handle") from a lwpolyline, which might imply that I am learning something.

I look into the help files, and searched the board(s). I look for references to lambda, and cross referenced function,  ' and list, mapcar and apply. Lambda is defining an anonymous function  (< (car a) (car b)), and passing the result through function, which is the same as ', but allows for optimization, which passes that result to vl-sort to use on the list lst.

I typed it myself, and it still is at least 50% gibberish to me.

Would someone explain in their own words what is happening here, please? I am wanting, at this point in the program, to change the nature of the list sorted to include a points list for the polyline, because this would be the easiest time to get it, rather than grabbing the handle and (entget (handent)).

I am guessing there is a way. Maybe
 
Code: [Select]
(("101" "3E16F" ((x y)(x y) (x y)....)("102" "3E0C3")((x1 y1)(x2 y2]) (x3 y3)....)... )
or
(("101" ("3E16F" (x y)(x y) (x y)....)("102" "3E0C3")((x1 y1)(x2 y2) (x3 y3)....)... )
or even
(("101" '("3E16F" (x y)(x y) (x y)....)("102" "3E0C3")((x1 y1)(x2 y2) (x3 y3)....)... )

Understanding is what I am after.

thanks,

roy
Title: Re: lambda
Post by: MP on March 31, 2009, 02:53:38 PM
Before going on a superfluous winded discussion ... does this clarify?

(defun foo ( a b ) (< (car a) (car b)))

(vl-sort lst 'foo)
Title: Re: lambda
Post by: MP on March 31, 2009, 02:55:41 PM
Perhaps this will help (http://www.theswamp.org/index.php?topic=2953.msg37000#msg37000).
Title: Re: lambda
Post by: curmudgeon on March 31, 2009, 03:23:03 PM
that helped very much.
I'll try to keep the winds down.
Title: Re: lambda
Post by: MP on March 31, 2009, 03:34:16 PM
Glad it helped curmudgeon, let us know if you need clarity on anything :).

PS: The wind reference was about me: I can go off on long winded explanations only to find out I went down some road no one cares about; just trying to avoid the resulting (http://www.theswamp.org/screens/mp/facepalm.gif).
Title: Re: lambda
Post by: Mark on March 31, 2009, 03:38:46 PM
I believe Stig Madsen did an explanation on mapcar/lambda as well but I can't seem to find. :(
Title: Re: lambda
Post by: Spike Wilbury on March 31, 2009, 03:54:19 PM
I believe Stig Madsen did an explanation on mapcar/lambda as well but I can't seem to find. :(

I recall one by Vladimir Nesterovsky - it must be on the web (still)....from many moons ago
Title: Re: lambda
Post by: CAB on March 31, 2009, 11:17:37 PM
I believe Stig Madsen did an explanation on mapcar/lambda as well but I can't seem to find. :(
Maybe this?
http://www.theswamp.org/index.php?topic=340.0


PS Brings back happy memories. Those were my early days just learning the language.  :-)
Title: Re: lambda
Post by: JohnK on April 01, 2009, 08:56:36 AM
I believe Stig Madsen did an explanation on mapcar/lambda as well but I can't seem to find. :(

I recall one by Vladimir Nesterovsky - it must be on the web (still)....from many moons ago

Vladimir's page is still up. [ http://vnestr.tripod.com/ ]

His explanation.
[ http://members.tripod.com/~vnestr/mapcar.txt ]
Title: Re: lambda
Post by: MP on April 01, 2009, 09:26:34 AM
I miss Vladimir, he was like Tony Lite: all the intellect, none of the attitude.
Title: Re: lambda
Post by: JohnK on April 01, 2009, 09:49:01 AM
I learned a lot from his web pages. Of course i learn a lot from everyone everywhere too.

I talked to him via email a couple of times and i tried to get him to take part in the challenges here (back when we were having them on a regular basis) but he never did show up. Last i heard he was big on Haskell.
Title: Re: lambda
Post by: TimSpangler on April 01, 2009, 12:00:11 PM
I miss Vladimir, he was like Tony Lite: all the intellect, none of the attitude.


 :-D

Title: Re: lambda
Post by: hermanm on April 02, 2009, 11:24:37 AM
Perhaps this will help (http://www.theswamp.org/index.php?topic=2953.msg37000#msg37000).

Only comment:
might want to use (function (lambda <yada yada>)) instead of quote

Thx to LE for pointing this out many moons ago
Title: Re: lambda
Post by: Spike Wilbury on April 02, 2009, 11:34:23 AM
Perhaps this will help (http://www.theswamp.org/index.php?topic=2953.msg37000#msg37000).

Only comment:
might want to use (function (lambda <yada yada>)) instead of quote

Thx to LE for pointing this out many moons ago

Are you Herman?.... from the old happy days at the autolisp customization ng from adesk, if so I'm glad to see you around here!!!!!! (I mean read you) - have been a long time, Sir. :)

Luis Esquivel.
Title: Re: lambda
Post by: MP on April 02, 2009, 11:36:34 AM
Are you Herman?.... from the old happy days at the autolisp customization ng from adesk?

My guess is ... Herman Mayfarth. :)
Title: Re: lambda
Post by: ronjonp on April 02, 2009, 11:39:36 AM
Are you Herman?.... from the old happy days at the autolisp customization ng from adesk?

My guess is ... Herman Mayfarth. :)

My guess  :-P
Title: Re: lambda
Post by: TimSpangler on April 02, 2009, 11:45:47 AM
Are you Herman?.... from the old happy days at the autolisp customization ng from adesk?

My guess is ... Herman Mayfarth. :)

My guess  :-P


Abit off topic, but.

I did a job for his wife many moons ago (Deb Gwynne) shortly after his passing (They lived in Taneytown, MD)

She looks very similar to the picture of his portrayed character...Herman. :whistle:  Scary!!
Title: Re: lambda
Post by: MP on April 02, 2009, 11:51:59 AM

I did a job for his wife many moons ago (Deb Gwynne) shortly after his passing (They lived in Taneytown, MD)

Mr. Mayfarth passed? I'm sorry to hear that; I did not know; apologies
Title: Re: lambda
Post by: hermanm on April 02, 2009, 02:01:23 PM
</cloak>
And a big "howdy" to MP, LE , et. al., from Corona, Calif.

Herman Mayfarth
www.tktn.com

:)

...return with us now, to those thrilling days of yesteryear, to the exploits of GO ACAD & cca
yeah, I miss Vlad's voice, too. very bright guy, & interesting to type to (what MP said)

Later,

hm

:)
Title: Re: lambda
Post by: MP on April 02, 2009, 02:13:30 PM
My guess is ... Herman Mayfarth. :)

I did a job for his wife many moons ago (Deb Gwynne) shortly after his passing (They lived in Taneytown, MD)

And a big "howdy" to MP, LE , et. al., from Corona, Calif.

Herman Mayfarth

wut
Title: Re: lambda
Post by: TimSpangler on April 02, 2009, 02:21:08 PM
Referring to "Herman Munster" (as pictured above) aka Fred Gwynne.... the actor

not referring to Herman Mayfarth aka AutoCAD aficionado....


BTW... good to see/read you again Herman, will you be around?
Title: Re: lambda
Post by: MP on April 02, 2009, 02:29:10 PM
Referring to "Herman Munster" (as pictured above) aka Fred Gwynne.... the actor

*dagnabbit* I swear that picture wasn't there before. (http://www.theswamp.org/screens/mp/facepalm.gif)

Anyway, good to see Herman's mug around here. :)

<MP=Michael Puckett>