Page 1 of 1

The length of nil value

Posted: Wed Apr 18, 2012 3:10 am
by iNPRwANG
This is code:

Code: Select all

(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

Re: The length of nil value

Posted: Wed Apr 18, 2012 3:35 am
by rickyboy
Because (length 'nil) is 3.

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

Re: The length of nil value

Posted: Wed Apr 18, 2012 3:45 am
by Lutz
Length applied to a symbol returns the length of the symbol name:

http://www.newlisp.org/downloads/newlis ... tml#length

Re: The length of nil value

Posted: Wed Apr 18, 2012 4:37 am
by iNPRwANG
OK, thx.
The difference with common lisp is: In common lisp the (length 'nil) is zero, and in newlisp is the symbols length.