The length of nil value

Started by iNPRwANG, April 17, 2012, 08:10:04 PM

Previous topic - Next topic

iNPRwANG

This is code:



(setq mylst '(nil nil nil nil nil nil nil nil nil nil nil nil))
(dolist (item mylst) (println (length item)))


Why the result is:



3

3

3

3

3

3

3

3

3

3

3

3

3

3

3

3

3

3

3

3

3

3

3

3

rickyboy

#1
Because (length 'nil) is 3.



On the other hand, (length nil) is 0.
(λx. x x) (λx. x x)

Lutz

#2
Length applied to a symbol returns the length of the symbol name:



http://www.newlisp.org/downloads/newlisp_manual.html#length">http://www.newlisp.org/downloads/newlis ... tml#length">http://www.newlisp.org/downloads/newlisp_manual.html#length

iNPRwANG

#3
OK, thx.

The difference with common lisp is: In common lisp the (length 'nil) is zero, and in newlisp is the symbols length.