help-gnu-emacs
[Top][All Lists]
Advanced

[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 {}.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]