Computer science: LISP: ideas about true and false

Self-tutoring about Comp Sci: the tutor mentions true and false in LISP.

An interesting aspect of every computer language is what it thinks of as “true” vs “false”. Many languages think 0 is false, while any other declared value, such as “hello” or even -1, is true. JavaScript, for instance, seems to see it that way, in my experience.

Note herein the difference between 0 (zero) and () (empty brackets), since they may look almost the same on some browsers.

LISP, however, seems to see it differently: anything defined as something other than nil or () is true, even if it’s defined as 0. LISP doesn’t have false; just nil. The only way to attain nil value is to be declared nil or () or else to arrive there by calculation.

In LISP, as in some other computer languages, an undefined (or undeclared) variable isn’t nil (or false); rather, the interpreter will complain when it encounters one.

So, a main thought: in LISP, (or 0 1) evaluates to 0, which is “not false”. However, (or nil) evaluates to nil, which is false, in LISP.

Surprising, eh?

Source:

cs.cmu.edu

Jack of Oracle Tutoring by Jack and Diane, Campbell River, BC.

Leave a Reply