Page 1 of 1

returning the empty list

Posted: Tue Jan 13, 2004 10:21 pm
by Sammo
shouldn't both return ()?

> (if true '() '())
()

> (if nil '() '())
nil

Posted: Wed Jan 14, 2004 1:43 am
by Lutz
'if' can take multiple condition/action pairs similar o 'cond' but wihtout the parenthesis, so it take the last '() as a condition and evaluates it. As it evluates to logigal nil it returns nil.

I agree that this very un-intuitive, and will change the behaviour for both 'if' and 'cond', so in the future:

(if nil '() '()) => () ; previously nil
and

(cond (nil 1) (nil 2) ('())) => () ; previously nil

Lutz