returning the empty list

For the Compleat Fan
Locked
Sammo
Posts: 180
Joined: Sat Dec 06, 2003 6:11 pm
Location: Loveland, Colorado USA

returning the empty list

Post by Sammo »

shouldn't both return ()?

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

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

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post 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

Locked