The length of nil value

Q&A's, tips, howto's
Locked
iNPRwANG
Posts: 32
Joined: Sun May 08, 2011 1:45 pm

The length of nil value

Post 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

rickyboy
Posts: 607
Joined: Fri Apr 08, 2005 7:13 pm
Location: Front Royal, Virginia

Re: The length of nil value

Post by rickyboy »

Because (length 'nil) is 3.

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

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

Re: The length of nil value

Post by Lutz »

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

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

iNPRwANG
Posts: 32
Joined: Sun May 08, 2011 1:45 pm

Re: The length of nil value

Post 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.

Locked