From: Mark Skilbeck <m@iammark.us>
To: Thorsten Jolitz <tjolitz@gmail.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: 'length' function for lists and cons cells?
Date: Fri, 22 Mar 2013 07:27:50 +0000 [thread overview]
Message-ID: <20130322072749.GD13119@earth> (raw)
In-Reply-To: <87ip4kkvl8.fsf@gmail.com>
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.
>
next prev parent reply other threads:[~2013-03-22 7:27 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.22586.1363890109.855.help-gnu-emacs@gnu.org>
2013-03-21 20:49 ` 'length' function for lists and cons cells? Pascal J. Bourguignon
2013-03-22 2:38 ` Thorsten Jolitz
2013-03-22 7:27 ` Mark Skilbeck [this message]
2013-03-22 9:57 ` Thorsten Jolitz
[not found] ` <mailman.22632.1363946271.855.help-gnu-emacs@gnu.org>
2013-03-23 12:19 ` Pascal J. Bourguignon
2013-03-23 15:35 ` Drew Adams
[not found] ` <mailman.22706.1364052941.855.help-gnu-emacs@gnu.org>
2013-03-23 15:52 ` Pascal J. Bourguignon
2013-03-24 5:20 ` Drew Adams
[not found] ` <mailman.22618.1363919920.855.help-gnu-emacs@gnu.org>
2013-03-22 7:45 ` Barry Margolin
2013-03-23 11:31 ` Pascal J. Bourguignon
2013-03-21 18:21 Thorsten Jolitz
2013-03-21 20:02 ` Stephen Berman
2013-03-21 21:58 ` Thorsten Jolitz
2013-03-21 22:05 ` Drew Adams
[not found] ` <mailman.22591.1363903134.855.help-gnu-emacs@gnu.org>
2013-03-23 11:24 ` Pascal J. Bourguignon
2013-03-21 20:10 ` Drew Adams
2013-03-21 22:09 ` Thorsten Jolitz
[not found] ` <mailman.22588.1363896620.855.help-gnu-emacs@gnu.org>
2013-03-25 15:24 ` duthen.cnv
2013-03-25 20:02 ` Pascal J. Bourguignon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130322072749.GD13119@earth \
--to=m@iammark.us \
--cc=help-gnu-emacs@gnu.org \
--cc=tjolitz@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.