From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Thorsten Jolitz Newsgroups: gmane.emacs.help Subject: Re: 'length' function for lists and cons cells? Date: Fri, 22 Mar 2013 03:38:11 +0100 Message-ID: <87ip4kkvl8.fsf@gmail.com> References: <87sj3opjfw.fsf@kuiper.lan.informatimago.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1363919926 19911 80.91.229.3 (22 Mar 2013 02:38:46 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 22 Mar 2013 02:38:46 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Mar 22 03:39:13 2013 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UIrst-00056O-UM for geh-help-gnu-emacs@m.gmane.org; Fri, 22 Mar 2013 03:39:12 +0100 Original-Received: from localhost ([::1]:33342 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UIrsW-0003yN-Jh for geh-help-gnu-emacs@m.gmane.org; Thu, 21 Mar 2013 22:38:48 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:33151) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UIrsI-0003po-E8 for help-gnu-emacs@gnu.org; Thu, 21 Mar 2013 22:38:39 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UIrsD-0003f0-63 for help-gnu-emacs@gnu.org; Thu, 21 Mar 2013 22:38:34 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:40003) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UIrsD-0003eu-03 for help-gnu-emacs@gnu.org; Thu, 21 Mar 2013 22:38:29 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1UIrsW-0004sK-Ou for help-gnu-emacs@gnu.org; Fri, 22 Mar 2013 03:38:48 +0100 Original-Received: from g231234180.adsl.alicedsl.de ([92.231.234.180]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 22 Mar 2013 03:38:48 +0100 Original-Received: from tjolitz by g231234180.adsl.alicedsl.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 22 Mar 2013 03:38:48 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 39 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: g231234180.adsl.alicedsl.de User-Agent: Gnus/5.130002 (Ma Gnus v0.2) Emacs/24.2 (gnu/linux) Cancel-Lock: sha1:lsBCVjd9F4uMwITJSka/gRWT7Ok= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:89652 Archived-At: "Pascal J. Bourguignon" 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. -- cheers, Thorsten