4 ms·
Common Lisp has a global variable called read-base ,which controls also base numbers are read in with. This, IIRC, was put in because some earlier Lisps read nu
by krzysz00 15y ago
Common Lisp has a global variable called read-base ,which controls also base numbers are read in with. This, IIRC, was put in because some earlier Lisps read numbers in octal, while others used decimal. Setting this variable to something higher than 10 can give you strange results. For example,
nil
=> NIL
(eql '() nil)
=> T
(setf *read-base* 36)
nil
=> 30477
(eql '() nil)
ERROR: 19101 is not a function name; try using a symbol instead
(|EQL| '() nil)
=> NIL
For you non-lispers, the empty list '() is equal to the "false" value, nil. Also, the pipes are special syntax to allow for symbols which normally not parse as symbols. (The uppercase is for historical reasons too).
The moral of this story: "See that control variable over there, the one that does weird things to parsing? Don't touch it unless you know what you're doing."
- RodgerTheGreat 15y agoI presume that CL standardized on a base as a default, though? Otherwise you have an appropriately recursive problem that every base is "base-10" in that base. edit: (setf read-base (+ 1 1 1 1 1 1 1 1 1 1)) :)
- krzysz00 15y agoI just went and checked, and the standard gives a default value of "10." for read-base , so decimal by default (I think). It also says: "Notes: Altering the input radix can be useful when reading data files in special formats. "