[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:31:37 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux) |
Thorsten Jolitz <tjolitz@gmail.com> writes:
> "Pascal J. Bourguignon" <pjb@informatimago.com> writes:
>
>> I don't understand what you want to do.
>
> well, avoid the errors I get when mapping alists with true lists and
> cons cells as elements with functions like 'lenght of 'cdr etc.
>
>> You can use length and dolist on alists and it will work perfectly:
>> (length '((a . 1) (b . 2) (c . 3)))
>> --> 3
>
> yes, but, when mapping the elements:
>
> ,------------------------------------------------------------
> | (length '(a . 1))
This is not an a-list, this is a dotted-list.
Note that a-list entries can be proper-list, if the value is a
proper-list, or circular lists, if the value is a circular list:
(defvar *a*
'((proper-list . (un one uno))
(circular-list . (deux . #1=(two dos . #1#)))
(dotted-list . (un . deux))
(single-cell-dotted-list . single)))
*a* --> ((proper-list un one uno)
(circular-list deux . #1=(two dos . #1#))
(dotted-list un . deux)
(single-cell-dotted-list . single))
(cdr (assoc 'proper-list *a*)) --> (un one uno)
(cdr (assoc 'circular-list *a*)) --> (deux . #1=(two dos . #1#))
(cdr (assoc 'dotted-list *a*)) --> (un . deux)
(cdr (assoc 'single-cell-dotted-list *a*)) --> single
--
__Pascal Bourguignon__ http://www.informatimago.com/
A bad day in () is better than a good day in {}.
- Re: 'length' function for lists and cons cells?, (continued)
- Re: 'length' function for lists and cons cells?, Pascal J. Bourguignon, 2013/03/21
- Re: 'length' function for lists and cons cells?, Thorsten Jolitz, 2013/03/21
- Re: 'length' function for lists and cons cells?, Mark Skilbeck, 2013/03/22
- Re: 'length' function for lists and cons cells?, Thorsten Jolitz, 2013/03/22
- Message not available
- Re: 'length' function for lists and cons cells?, Pascal J. Bourguignon, 2013/03/23
- RE: 'length' function for lists and cons cells?, Drew Adams, 2013/03/23
- Message not available
- Re: 'length' function for lists and cons cells?, Pascal J. Bourguignon, 2013/03/23
- RE: 'length' function for lists and cons cells?, Drew Adams, 2013/03/24
Message not available
Message not available
- Re: 'length' function for lists and cons cells?,
Pascal J. Bourguignon <=