Subject: Re: UT_Pair car and cdr
smith@missioncriticallinux.com
Date: Fri Jun 01 2001 - 07:47:10 CDT
"Sean R. Bright" said:
>> From: owner-abiword-dev@abisource.com
>> [mailto:owner-abiword-dev@abisource.com]On Behalf Of Mike Nordell
>> Sent: Thursday, May 31, 2001 7:55 PM
>> To: AbiWord-dev
>> Subject: Re: UT_Pair car and cdr
>>
>>
>> Patrick Lam wrote:
>> [Mike informing of the C++ way]
>
>...
>
>> "car" and "cdr". These TLAs has absolutely no meaning in C++,
>> not to mention
>> the fact that they are *completely wrong* to use in a "pair".
>
>I beg to differ. A cons in Lisp is effectively a linked list node and
>therefore "car" points to the first element and "cdr" points to the second
>element. The fact that the second element in the node is a list is
>irrelevant.
Actually, a car points to the first element, and the cdr points to THE
REST OF THE LIST (not the second element). It actually returns a list.
Example:
you have a list (1 2 3 4 5)
(car '(1 2 3 4 5)) => 1
(cdr '(1 2 3 4 5)) => (2 3 4 5)
A two element list still works the same way (just tested with GUILE):
(car '(a b)) => a
(cdr '(a b)) => (b)
To get b, you need to use:
(car (cdr '(a b))) => b
If the above is not what Abiword is doing, but is pulling out the 1st &
2nd elements of the lists, it's probably better to rename them. car and
cdr have very well defined behavior in the languages that support them.
On the other hand, maybe we do want car & cdr behavior - basically popping
the 1st element off of a list, and returning either the 1st element or the
rest of the list.
jeff
-----------------------------------------------------------------------
Jeffry Smith Technical Sales Consultant Mission Critical Linux
smith@missioncriticallinux.com phone:603.930.9739 fax:978.446.9470
-----------------------------------------------------------------------
Thought for today: fragile adj.
Syn brittle.
This archive was generated by hypermail 2b25 : Fri Jun 01 2001 - 07:47:41 CDT