[OT] Lisp IS fun! was Re: Who modified my local variable?

Levi Pearson levi at cold.org
Tue Jun 13 17:04:28 MDT 2006


On Jun 13, 2006, at 4:46 PM, Derek Davis wrote:

> On 6/13/06, Gregory Hill <Gregory_Hill at tni.com> wrote:
>> I meant the 2nd half of the list, Ruby/Python/Perl.   I've actually
>
> To be clear for the Lisp guy, you probably should have said  
> something more like
> cdddr(C, C++, Java, ruby, python, perl).
>
>>
>> Greg
>
> Derek
>
> P.S.  I know, the syntax is probably wrong.  That wasn't the point, so
> I didn't bother to look it up. :)

It was close!

(cdddr '(C C++ Java Ruby Python Perl))
=> (Ruby Python Perl)

Lisp Trivia:  The functions car and cdr in Lisp come from the  
assembly language mnemonics 'Contents of Address Register' and  
'Contents of Decrement Register' that were used on the machines that  
early lisps were programmed on.  Since a lisp list is a linked list  
of data pairs (called cons pairs in lisp lingo), the car instruction  
grabbed the first item and the cdr instruction grabbed the pointer to  
the next pair.  Thus, the names made perfect sense for those early  
implementations.  So, why do we still use them?

Well, the above example is probably a big part of it.  Lisp allows  
you to compose multiple car and cdr operations into a single  
expression by adding arbitrary a's and d's between the c and r.   
There are now aliases 'first' and 'rest' for 'car' and 'cdr', but  
they don't compose like car and cdr do.  Peter Norvig, in his style  
guide, also suggests using the new aliases when referring to data  
that is meant to be a list, and car/cdr when the data is meant to be  
a tree or some other structure in order to bettery convey intent.

			--Levi



More information about the PLUG mailing list