[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: lisp performace question: how efficent are (long) list parameters?
From: |
David Kastrup |
Subject: |
Re: lisp performace question: how efficent are (long) list parameters? |
Date: |
10 Jan 2004 17:53:27 +0100 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50 |
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