args | arguments of function |
forms | sequentially executed forms |
LAMBDA form creates function object associated with definition environment. This function object is called "closure". It can be applied later with funcall. Arguments of function can be regular (matched by position), optional (with default values), keyword (matched by keyword symbol) and rest (taking rest of arguments into a list). Lambda form don't have to be prefixed with "#'" syntax. Result of function application is value of the last form unless return function or nonlocal exit is executed.
(lambda (x) (+ x 3)) => <#closure>
(funcall (lambda (x y) (* x y) (+ x y)) 2 3) => 5
(funcall (lambda (&optional (one 1) (two 2)) (list one two))) => (1 2) (funcall (lambda (&optional (one 1) (two 2)) (list one two)) 10) => (10 2) (funcall (lambda (&optional (one 1) (two 2)) (list one two)) 10 20) => (10 20)
(funcall (lambda (&rest myargs) (length myargs))) => 0 (funcall (lambda (&rest myargs) (length myargs)) 4 5 6) => 3 (funcall (lambda (&rest myargs) (length myargs)) '(4 5 6)) => 1
(funcall (lambda (&key one two) (list one two))) => (NIL NIL) (funcall (lambda (&key one two) (list one two)) :two 7) => (NIL 7) (funcall (lambda (&key one two) (list one two)) :two 7 :one 4) => (4 7)