View unanswered posts | View active topics It is currently Sun Sep 05, 2010 3:07 am



Post new topic Reply to topic  [ 4 posts ] 
first gives errors on empty lists 
Author Message

Joined: Sun May 10, 2009 3:11 am
Posts: 15
Post first gives errors on empty lists
Calling (first) on an empty list gives an error instead of returning the empty list. This is inconsistent with the documentation, which claims that first behaves the same as car in other Lisp implementations.

On the contrary,

Code:
; sbcl
This is SBCL 1.0.18.debian, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http>.

* (car nil)

NIL

* (car ())

NIL


CL (and Scheme as well, I believe) return empty lists when car or cdr (which are first and rest in NL) are called on empty lists.

This behavior of the function gives a lot of errors in instances where lists are being checked using functions such as filter, which may return empty lists. I doubt that modifying this behavior would cause existing programs to break.


Wed May 20, 2009 7:20 pm
Profile

Joined: Thu Sep 26, 2002 4:45 pm
Posts: 4159
Location: Boca Raton, Florida
Post 
In Common Lisp 'nil' is a list terminator in newLISP 'nil' is a boolean value only. Consider this in SBCL:

Code:
* (car '())

NIL
* (car '(nil))

NIL
*


but in Scheme and newLISP things are similar, in SISC (R5RS Scheme) :

Code:
#;> (car '())
Error in car: expected type pair, got '()'.
console:3:1: <from>
#;> (car '(nil))
nil
#;>


and in newLISP similar:

Code:
> (first '())

ERR: list is empty in function first : '()
> (first '(nil))
nil
>


Both Scheme and newLISP give an error when using 'car' or 'first' on an empty list. The documentation does not use the word same but uses the weaker equivalent. I don't want to go too much into these type of differences in the newLISP manual, but I could add your observation here:

http://www.newlisp.org/index.cgi?page=D ... ther_LISPs

perhaps an additional paragraph after the explanations about 'cons' or in the paragraph about 'nil' and 'true'.


Wed May 20, 2009 7:50 pm
Profile E-mail WWW

Joined: Sun May 10, 2009 3:11 am
Posts: 15
Post 
Right, maybe this is just another "nil is not ()" difference with Common Lisp. Sorry, CL was what taught me how to think Lisp.


Wed May 20, 2009 10:32 pm
Profile

Joined: Thu Sep 26, 2002 4:45 pm
Posts: 4159
Location: Boca Raton, Florida
Post 
Many of the differences between CL and newLISP have their root in the fact that CL is designed to be compiled, while newLISP is a dynamic, interpreted and code equals data language.

Apart from those differences you will find enough other things in newLISP being similar to what attracted you to Lisp in the first place.


Thu May 21, 2009 1:16 am
Profile E-mail WWW
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Forum style by Vjacheslav Trushkin for Free Forums/DivisionCore.