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: Mark Skilbeck
Subject: Re: 'length' function for lists and cons cells?
Date: Fri, 22 Mar 2013 07:27:50 +0000
User-agent: Mutt/1.5.21 (2010-09-15)

It just doesn't make sense to talk about the length of a dotted
_pair_, a cons-cell: it has a car and a cdr.

On Fri, Mar 22, 2013 at 03:38:11AM +0100, Thorsten Jolitz wrote:
> "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))
> | 
> | Debugger entered--Lisp error: (wrong-type-argument listp 1)
> |   length((a . 1))
> `------------------------------------------------------------
> 
> > (dolist (entry '((a . 1) (b . 2) (c . 3)))
> >   (destructuring-bind (key . value) entry
> >      (insert (format "key = %S, value = %S\n" key value))))
> > key = a, value = 1
> > key = b, value = 2
> > key = c, value = 3
> 
> I wasn't aware of destructuring-bind, thats cl stuff - had to look it up here:
> http://dto.github.com/notebook/require-cl.html#sec-6-6
> 
> > If you want to count the cons cells, then why stop at the
> > dotted-lists? There are also circular lists. See how you can do it at:
> > https://gitorious.org/com-informatimago/com-informatimago/blobs/master/common-lisp/cesarum/list.lisp#line303
> 
> ok, thanks for the hint. 
> 



reply via email to

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