I have been looking throught the Peter Norvig (Artificial Intelligence programming
:case studies in Common Lisp)
I am having trouble understanding some Lambda functions.
For instance the following function ....
(defun is (value)
#'lambda (x) (eql x value)))
Where does the x parameter come from ??
The documentation says that a successor function is returned - but
I am unable to find any references to this in the text.
Can anyone shed a little light here please ??!!
Kamal
Kamal Nazar (······@sis.port.ac.uk) wrote:
: I have been looking throught the Peter Norvig (Artificial Intelligence programming
: :case studies in Common Lisp)
: I am having trouble understanding some Lambda functions.
: For instance the following function ....
: (defun is (value)
: #'lambda (x) (eql x value)))
: Where does the x parameter come from ??
: The documentation says that a successor function is returned - but
: I am unable to find any references to this in the text.
: Can anyone shed a little light here please ??!!
: Kamal
First of all you missed a parenthesis before "lambda"
(defun is (value)
#'(lambda (x) (eql x value)))
To put it simply, function "is" returns a "function" which then can be
called ("funcalled") on one argument which will be passed to the parameter
"x".
for example:
(is 2)
will produce a function of one argument which will test its equality to 2.
Here it goes:
>(setq fun2 (is 2)) ;;create function to test for equality to 2.
(LAMBDA-CLOSURE ((VALUE 2)) () ((IS BLOCK #<@002E3418>)) (X)
(EQL X VALUE))
>(funcall fun2 1) ;;call that function on 1. (1 is passed as "x")
NIL
>(funcall fun2 2)
T
>(eql '(a b c) '(a b c))
NIL
>(setq fun0 (is 0)) ;;create function to test for equality to 0.
(LAMBDA-CLOSURE ((VALUE 0)) () ((IS BLOCK #<@002E3410>)) (X)
(EQL X VALUE))
>(funcall fun0 1)
NIL
>(funcall fun0 0)
T
>(funcall (is 3) 4)
NIL
>(funcall (is 3) 3)
T
Hope that helps.
Misha
-----------------------------------------------------------------------------+
Michael Tselman (Misha) Internet: ·····@ccs.neu.edu | Imagination is |
College of Computer Science, Northeastern University | more important |
23 Cullinane Hall, 360 Huntington Ave., Boston, MA 02115| than knowledge!|
Phone: (617)-373-3822, Fax: (617)-373-5121 | |
WWW: http://www.ccs.neu.edu/home/misha | (A. Einstein) |
-----------------------------------------------------------------------------+