Author Topic: lambda  (Read 2447 times)

0 Members and 1 Guest are viewing this topic.

curmudgeon

  • Newt
  • Posts: 192
lambda
« 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
Never express yourself more clearly than you are able to think.

MP

  • Seagull
  • Posts: 17454
Re: lambda
« Reply #1 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)
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

MP

  • Seagull
  • Posts: 17454
Re: lambda
« Reply #2 on: March 31, 2009, 02:55:41 PM »
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

curmudgeon

  • Newt
  • Posts: 192
Re: lambda
« Reply #3 on: March 31, 2009, 03:23:03 PM »
that helped very much.
I'll try to keep the winds down.
Never express yourself more clearly than you are able to think.

MP

  • Seagull
  • Posts: 17454
Re: lambda
« Reply #4 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 .
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

Mark

  • Custom Title
  • Seagull
  • Posts: 28685
Re: lambda
« Reply #5 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. :(
TheSwamp.org  (serving the CAD community since 2003)

Spike Wilbury

  • Guest
Re: lambda
« Reply #6 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

CAB

  • Global Moderator
  • Seagull
  • Posts: 10366
Re: lambda
« Reply #7 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.  :-)
« Last Edit: March 31, 2009, 11:25:45 PM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

John Kaul (Se7en)

  • Administrator
  • Needs a day job
  • Posts: 9268
Re: lambda
« Reply #8 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 ]
“Common sense is not so common.” ~Voltaire

--> Donate to TheSwamp.org <--

MP

  • Seagull
  • Posts: 17454
Re: lambda
« Reply #9 on: April 01, 2009, 09:26:34 AM »
I miss Vladimir, he was like Tony Lite: all the intellect, none of the attitude.
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

John Kaul (Se7en)

  • Administrator
  • Needs a day job
  • Posts: 9268
Re: lambda
« Reply #10 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.
“Common sense is not so common.” ~Voltaire

--> Donate to TheSwamp.org <--

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: lambda
« Reply #11 on: April 01, 2009, 12:00:11 PM »
I miss Vladimir, he was like Tony Lite: all the intellect, none of the attitude.


 :-D

ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

hermanm

  • Bull Frog
  • Posts: 282
Re: lambda
« Reply #12 on: April 02, 2009, 11:24:37 AM »
Perhaps this will help.

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

Thx to LE for pointing this out many moons ago
If you don't know where you are going, you might not get there.
  - L.P. Berra

Spike Wilbury

  • Guest
Re: lambda
« Reply #13 on: April 02, 2009, 11:34:23 AM »
Perhaps this will help.

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.

MP

  • Seagull
  • Posts: 17454
Re: lambda
« Reply #14 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. :)
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox