Ok Charles, I'm going to take a stab at this. Bear with me, I'm not the best teacher.
Ahhh lambda --
Use the lambda function when the overhead of defining a new function is not justified. It also makes the programmer's intention more apparent by laying out the function at the spot where it is to be used. This function returns the value of its last expr, and is often used in conjunction with apply and/or mapcar to perform a function on a list.
Trouble with the reference is that it shows only two examples, one for apply, and one for mapcar. It implies that's the only way it can be used.
As such, the calling syntax is the same for both, insomuch as you call lambda quoted --
(apply
'(lambda (x y z)
(* x (+ y z))
)
'(5 6 7)
)
=> 65
(mapcar
'(lambda (x)
(* x 25)
)
'(2 -4 6 -8 10)
)
=> (50 -100 150 -200 250)
Now think about this for a moment. If you were not using lambda how might you use apply and mapcar?
Couple examples --
(apply
'+
'(1 2 3)
)
=> 6
(mapcar
'itoa
'(1 2 3)
)
=> ("1" "2" "3")
Anything kind of leap off the page?
The functions passed to apply and mapcar were quoted.<voice=BasilFawlty>Ahhh, fascinating, completely rivoting. And salient perhaps ummm, how?</voice>
When you use apply and mapcar you need to quote the functions passed to it. Subtitle: You can use lambda unquoted where a function would be used unquoted.
Consider this --
(defun squarex (x)
(* x x)
)
To use --
(squarex 5)
=> 25
What if we didn't want the overhead of defining a function, but our code's readability (and maintainability) would be improved if we could define and use functionality precisely where we need it? Sounds like "lambda to the rescue" to me --
( (lambda (x)
(* x x)
)
5
)
=> 25
Perhaps laying out both horizontally will be more illuminating --
(squarex 5)
((lambda (x) (* x x)) 5)
Ding! Ding! Ding!
Another one to illustrate argument passing --
( (lambda (a b c)
(/ (+ a b) (float c))
)
1
2
4
)
=> 0.75
Did this help? Do you see now that I am not calling mapcar, explicitly or implicitly in my GetLayersFrozenInViewport function?
Perhaps you will view this
function in a new light.
Oh, just about forgot --
(entget
ename
'("acad") ;; <= this tells entget to retrieve the
;; extended entity data for registered
;; application name "acad". This is
;; where the frozen layer information
;; is stored and why we wants it. :)
)
(my, my these are big assed icons)