From: David Kastrup <dak@gnu.org>
Subject: Re: lisp performace question: how efficent are (long) list parameters?
Date: 10 Jan 2004 17:53:27 +0100 [thread overview]
Message-ID: <x5isjjkans.fsf@lola.goethe.zz> (raw)
In-Reply-To: m2brpblq2v.fsf@bella.local
leo <leo@bella.local> writes:
> hi there
>
> just a little thing for a lisp beginner. i have written a function:
>
> (defun first-free-position (positions)
> "returns the first free position in POSITIONS of all frames"
> (if positions
> (let ((list-of-frames (frame-list)))
> (if (frame-on-position (car positions) list-of-frames)
> (first-free-position (cdr positions))
> (car positions)))))
>
> this function recomputes `(frame-list)' for every recursion.
Recursion is not efficient in Elisp.
> so i thought to set `(frame-list)' to a variable which could be
> carried through as parameter:
>
> (defun first-free-position (positions all-frames)
> "returns the first free position in POSITIONS of all-frames."
> (if positions
> (if (frame-on-position (car positions) all-frames)
> (first-free-position (cdr positions) all-frames)
> (car positions))))
>
> called like `(first-free-position position-alist (frame-list))' this
> version computes (frame-list) only once, but the list `all-frames' is
> put every time on the parameter stack.
>
> so, what is more effiecent?
(defun first-free-position (positions)
(let ((list-of-frames (frame-list)) frame)
(while (and (setq frame (pop positions))
(frame-on-position frame list-of-frames)))
frame))
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
next prev parent reply other threads:[~2004-01-10 16:53 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-01-10 16:35 lisp performace question: how efficent are (long) list parameters? leo
2004-01-10 16:50 ` Joe Casadonte
2004-01-10 16:53 ` David Kastrup [this message]
2004-01-28 8:05 ` Kai Grossjohann
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=x5isjjkans.fsf@lola.goethe.zz \
--to=dak@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.