newLISP Fan Club

Forum => newLISP in the real world => Topic started by: iNPRwANG on April 17, 2012, 08:10:04 PM

Title: The length of nil value
Post by: iNPRwANG on April 17, 2012, 08:10:04 PM
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
Title: Re: The length of nil value
Post by: rickyboy on April 17, 2012, 08:35:44 PM
Because (length 'nil) is 3.



On the other hand, (length nil) is 0.
Title: Re: The length of nil value
Post by: Lutz on April 17, 2012, 08:45:47 PM
Length applied to a symbol returns the length of the symbol name:



http://www.newlisp.org/downloads/newlisp_manual.html#length
Title: Re: The length of nil value
Post by: iNPRwANG on April 17, 2012, 09:37:35 PM
OK, thx.

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