[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: 'length' function for lists and cons cells?
From: |
Pascal J. Bourguignon |
Subject: |
Re: 'length' function for lists and cons cells? |
Date: |
Sat, 23 Mar 2013 12:24:55 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux) |
Thorsten Jolitz <tjolitz@gmail.com> writes:
> Stephen Berman <stephen.berman@gmx.net> writes:
>
>>> which function could I use when I map an alist e.g. with dolist, that
>>> contains both types of associations as shown below: cons cells, or lists
>>> with 3 or more elements?
>>>
>>> 'length' doesn't work on cons cells:
>>
>> Since a cons cells always contains exactly two members (its car and its
>> cdr), why do you want to call a function to find its length?
>
> actually I'm looking for a way to distinguish between cons cells and
> regular lists to avoid the errors when mapping an alist that contains
> both with functions that work only on one of them, using 'length' was
> just a hack.
A-lists are proper lists, so I don't see what you're afraid of here.
But again, have a look at:
https://gitorious.org/com-informatimago/com-informatimago/blobs/master/common-lisp/cesarum/list.lisp#line96
> I would have thought that 'consp' might be the right function, but:
>
> ,-----------------------
> | (consp '("a" "b" "c"))
> | t
> |
> | (consp '("a" . "c"))
> | t
> `-----------------------
It can be used.
--
__Pascal Bourguignon__ http://www.informatimago.com/
A bad day in () is better than a good day in {}.