all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Pascal J. Bourguignon" <pjb@informatimago.com>
To: help-gnu-emacs@gnu.org
Subject: Re: 'length' function for lists and cons cells?
Date: Mon, 25 Mar 2013 21:02:59 +0100	[thread overview]
Message-ID: <87mwtrmemk.fsf@kuiper.lan.informatimago.com> (raw)
In-Reply-To: 54eefda1-7c85-4c18-8c02-5376dde008e0@googlegroups.com

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


  reply	other threads:[~2013-03-25 20:02 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-21 18:21 'length' function for lists and cons cells? 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 [this message]
     [not found] <mailman.22586.1363890109.855.help-gnu-emacs@gnu.org>
2013-03-21 20:49 ` Pascal J. Bourguignon
2013-03-22  2:38   ` Thorsten Jolitz
2013-03-22  7:27     ` Mark Skilbeck
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

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=87mwtrmemk.fsf@kuiper.lan.informatimago.com \
    --to=pjb@informatimago.com \
    --cc=help-gnu-emacs@gnu.org \
    /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.