(difference '(nil a) (list true nil))

Q&A's, tips, howto's
Locked
Kazimir Majorinc
Posts: 388
Joined: Thu May 08, 2008 1:24 am
Location: Croatia
Contact:

(difference '(nil a) (list true nil))

Post by Kazimir Majorinc »

It appears to be error:
  • (println (difference '(nil a) '(true nil))) ;=>(a)
    (println (difference '(nil a) (list true nil))) ;=>(nil a)

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

Post by Lutz »

This turns out to be a bug in the 'sort' function involved in 'difference'. What happens here is that the symbol 'nil' gets compared with the symbol 'a', then two symbols get compared by their names, but the symbol 'nil' should also be taken as the boolean value 'nil' and sort before the symbol 'a'.

Code: Select all

> (sort '(a nil)) => (a nil)
(sort (list 'a nil)) => (nil a) 
and:

Code: Select all

(difference (list nil 'a) (list true nil)) => (a)
(difference (list nil 'a) '(true nil)) => (a)

Locked