not or null

Pondering the philosophy behind the language
Locked
stellan
Posts: 2
Joined: Sun Mar 21, 2004 11:49 am
Location: Stockholm
Contact:

not or null

Post by stellan »

just a minor point. I think that (null something) feels more intuitive than (not something) if you are testing for nil or the empty list. Of course I can define a function null myself but still...

stellan

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

Post by Lutz »

this would define a global null which would works just like not and perform as efficiently:

(constant (global 'null) not)

you also could do one after the other:

(constant 'null not)
(global null)

But the first way is more elegant, now you can do:

(null '()) => true

(null nil) => true

Using 'constant' instead of 'set' will protect it against inadvertant change and the 'global' function makes 'null' available in any context/namespace, like the original 'not'.

Calling it 'null' makes it more like a predicate 'null?' while 'not' emphasizes its character as a logical negation operator.

Lutz

Locked