Can anyone explain how does listp in Lisp work ?
CL-USER 2 : 1 > (if (listp 1) (+ 1 2) (+ 3 4))
7
What's this about ?
So you have an "if" , a "listp 1" , a (+ 1 2) and a (+ 3 4) and the output result is 7. How does this work ?
listp
-
- Posts: 166
- Joined: Sun Nov 28, 2010 4:21 pm
Re: listp
IF is a SPECIAL-OPERATOR, it evaluates its first child for being non-NIL, if that's the case then it evaluates its second child and returns that as its result, or else it evaluates its third child and returns that.
(LISTP 1) evaluates to NIL, because 1 is not a CONS, so it evaluates (+ 3 4)
+ is the function that adds all of its arguments together, (+ 3 4) evaluates to 7
(LISTP 1) evaluates to NIL, because 1 is not a CONS, so it evaluates (+ 3 4)
+ is the function that adds all of its arguments together, (+ 3 4) evaluates to 7