Newsgroups: comp.lang.lisp
Path: cantaloupe.srv.cs.cmu.edu!rochester!udel!news.mathworks.com!newshost.marcam.com!zip.eecs.umich.edu!caen!hearst.acc.Virginia.EDU!murdoch!elvis.med.Virginia.EDU!sdm7g
From: sdm7g@elvis.med.Virginia.EDU (Steven D. Majewski)
Subject: Re: Behaviour of MAPCAR
X-Nntp-Posting-Host: elvis.med.virginia.edu
Message-ID: <DBx9o2.DMD@murdoch.acc.Virginia.EDU>
Sender: usenet@murdoch.acc.Virginia.EDU
Organization: University of Virginia
References: <3udfe7$66h@sparcserver.lrz-muenchen.de> <3ue74e$4lr@camelot.ccs.neu.edu>
Date: Tue, 18 Jul 1995 17:24:01 GMT
Lines: 57


>Stephan Kepser (kepser@cis.uni-muenchen.de) wrote:
>: Hi,
>
>: when debugging my program I discovered the following behaviour of MAPCAR  
>: (in Lucid CommonLisp v.4.1.1), which astonished me:
>
>: >(mapcar #'(lambda (x) '*a*) '(a b)
>: (*a* *a*)
>
>: >(mapcar #'(lambda (x) '*a*) '(a . b)
>: (*a*)
>

In article <3ue74e$4lr@camelot.ccs.neu.edu>,
Michael Tselman <misha@ccs.neu.edu> wrote:
>
>Read page 30 of CLtL2. In particular it says (last paragraph):
>	"... Most functions advertised to operate on lists expect to be given
>	true lists. Throughout this book, unless otherwise specified, it is
>	an error to pass a dotted list to a function that is specified to
>	require a list as an argument."
>

I missed that note, however, as I noted to Stephan Kepser in email,
that even without that note and assuming it was ambiguous whether 
mapcar should work on dotted lists, his expectation of how it ought
to work is NOT one of the reasonable alternatives:

>: The first operation, the one on true (i.e. non-dotted) lists, works as  
>: expected. But what about the second? Obviously, the function (lambda (x)  
>: '*a*) is only applied to the car of (a . b). Since the cdr is a non-NIL  
>: element, one may (and indeed I did) have expected that the function is  
>: applied to the cdr, too.

The reasonable alternatives are either: 
 (1) That it's an error ( which, if the implemantation  does no other
   checking, will likely happen when trying to take the CAR of 'b ) 
 (2) That the definition says the function is applied to the
 successive CAR's - it doesn't mention the CDRs of the list, although 
 "successive" implies "recursive" which implies what it's recursing 
  on are the successive CDRs. 

In neither interpretation, should one *ever* expect the mapped function
to be applied to the CDR, and the fact that the final CDR is somehow
special doesn't make any difference. 


That paragraph may remove the ambiguity, but Stephan's expectation -
that the function be applied to the cdr - was never an option. 


---|  Steven D. Majewski   (804-982-0831)  <sdm7g@Virginia.EDU>  |---
---|  Computer Systems Engineer          University of Virginia  |---
---|  Department of Molecular Physiology and Biological Physics  |---
---|  Box 449 Health Science Center    Charlottesville,VA 22908  |---
 [ "The grass is always greener, except at t=0" - Stan Kelly-Bootle ]
