Page 1 of 1

listp

Posted: Sat Jun 03, 2017 9:44 am
by GengyangCai
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 ?

Re: listp

Posted: Sat Jun 03, 2017 10:35 am
by pjstirling
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