From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Pascal J. Bourguignon" Newsgroups: gmane.emacs.help Subject: Re: 'length' function for lists and cons cells? Date: Mon, 25 Mar 2013 21:02:59 +0100 Organization: Informatimago Message-ID: <87mwtrmemk.fsf@kuiper.lan.informatimago.com> References: <87620k7gwm.fsf@gmail.com> <54eefda1-7c85-4c18-8c02-5376dde008e0@googlegroups.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1364274683 24446 80.91.229.3 (26 Mar 2013 05:11:23 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 26 Mar 2013 05:11:23 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Mar 26 06:11:49 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 1UKMAk-0004Uc-SW for geh-help-gnu-emacs@m.gmane.org; Tue, 26 Mar 2013 06:11:46 +0100 Original-Received: from localhost ([::1]:44954 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKMAM-0004qH-KT for geh-help-gnu-emacs@m.gmane.org; Tue, 26 Mar 2013 01:11:22 -0400 Original-Path: usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 42 Original-X-Trace: individual.net +qQ9RbBd7vYHDQkwAMe1vwhhi2Ba9Jp7t9GtyNRDc/rxRH1TIu Cancel-Lock: sha1:NDFjZDcxMDBmY2Q1M2ZjNjlhODM4MDdlM2U4YTY3NGQ3ZjQwY2NkYQ== sha1:SiDQLIg1Xv41rcT2rp9vkQXhE5I= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux) Original-Xref: usenet.stanford.edu gnu.emacs.help:197478 X-Mailman-Approved-At: Tue, 26 Mar 2013 01:09:48 -0400 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:89755 Archived-At: duthen.cnv@gmail.com writes: > Considering that: > (a b) contains 2 cons cells and 2 values (a and b), > (a b . c) contains 2 cons cells and 3 values (a b and c), > (a b c) contains 3 cons cells and 3 values (a b and c). > > So, one possible point of vue (not necessarily mine, though!) > could consider that (a b . c) is "a little bit longer" than (a b) > and "a little bit shorter" than (a b c)! > > Hence, the function: > (defun semi-length (xs) > (cond ((null xs) 0) > ((atom xs) .5) > (t (1+ (semi-length (cdr xs)))))) > > (mapcar (lambda (x) (cons (semi-length x) x)) > '(() > a > (a) > (a . b) > (a b) > (a b . c) > (a b c))) > > ((0) (0.5 . a) (1 a) (1.5 a . b) (2 a b) (2.5 a b . c) (3 a b c)) > > A true list is just one whith an integer semi-length > whereas a dotted-paired list is one with a fractional semi-length ! :) Nice. And since circular lists have a stem length and a loop length, with the loop length >0, we can represent them as complex numbers, perhaps something like: (* (+ stem-length loop-length) (expt (sqrt -1) (/ stem-length loop-length))) -- __Pascal Bourguignon__ http://www.informatimago.com/ A bad day in () is better than a good day in {}.