; apply - apply a function to the whole list:
; mapcar - map a function to every element in the list:
; function/quote/apostrophe are used to unevaluate the subfunction, so it could be passed to a function like apply/mapcar:
_$
(lambda (x
) (strcat (strcase x
) (strcase x t
))) -> #
<USUBR @000000be6614b2f0
-lambda
-> ; evaluated function, it won't work with apply/mapcar; the (function) function is used when compiling the code to .vlx, since the quote/apostrophe passes literally the subfunction to the mapcar/apply - and that messes-up the compiled code
; thats why (function foo) return is different than (quote foo) and 'foo
; So the above means that these are equivalent:
_$
(lambda (x
) (print x
)(princ)) -> #
<USUBR @000000be6614b480
-lambda
-> ; lambda - unnamed function_$
(defun myprint
(x
) (print x
)(princ)) -> MYPRINC
; define a named function
; So now the named (defun) and the unnamed (lambda) functions are equivalent - they do the same thing:
;(<function> <arguments>)
_$ (myprint "abc") -> "abc"
; As you can see the difference is that when (lambda) is an unnamed function, you must type what it should do to each element of the list, since (myprint) is already defined:
_$
(mapcar 'myprint '
("Hello" "World" "!"))
"Hello"
"World"
"!" ( )
"Hello"
"World"
"!" ( )
; so the above is like writing:
(myprint "Hello")
(myprint "World")
(myprint "!")
; and the same for (lambda):
; The reason to use (lambda) instead of (defun) is that you just want to make some function on the fly to perform a small operation, i.e.:
(lambda (a b
) (* (/ (+ a b
) 2.
) 5)) ; And you won't use it anywhere else