This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

listp

2 posts · 3201 views

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

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