all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* lisp performace question: how efficent are (long) list parameters?
@ 2004-01-10 16:35 leo
  2004-01-10 16:50 ` Joe Casadonte
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: leo @ 2004-01-10 16:35 UTC (permalink / raw)


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. 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?

cheers, leo

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: lisp performace question: how efficent are (long) list parameters?
  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
  2004-01-28  8:05 ` Kai Grossjohann
  2 siblings, 0 replies; 4+ messages in thread
From: Joe Casadonte @ 2004-01-10 16:50 UTC (permalink / raw)


On 11 Jan 2004, leo@bella.local wrote:

> so, what is more effiecent?

Run them each 1000 times and time them.  That should tell you for sure.

--
Regards,

joe
Joe Casadonte
jcasadonte@northbound-train.com

------------------------------------------------------------------------------
         Llama Fresh Farms => http://www.northbound-train.com
   Gay Media Resource List => http://www.northbound-train.com/gaymedia.html
            Perl for Win32 => http://www.northbound-train.com/perlwin32.html
               Emacs Stuff => http://www.northbound-train.com/emacs.html
          Music CD Trading => http://www.northbound-train.com/cdr.html
------------------------------------------------------------------------------
                       Live Free, that's the message!
------------------------------------------------------------------------------

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: lisp performace question: how efficent are (long) list parameters?
  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
  2004-01-28  8:05 ` Kai Grossjohann
  2 siblings, 0 replies; 4+ messages in thread
From: David Kastrup @ 2004-01-10 16:53 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: lisp performace question: how efficent are (long) list parameters?
  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
@ 2004-01-28  8:05 ` Kai Grossjohann
  2 siblings, 0 replies; 4+ messages in thread
From: Kai Grossjohann @ 2004-01-28  8:05 UTC (permalink / raw)


leo <leo@bella.local> writes:

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

Note that in Lisp, a list is just a pointer to a cons cell, and a cons
cell is a pair of pointers.  The car of a cons cell points to the
current list element, the cdr points to the next list element.  The
cdr pointer of the last element is nil.

So what is actually put on the parameter stack is just a pointer to
the first cons cell in the list all-frames.  All calls share the same
list.

Maybe you could read the Emacs Lisp Intro, it has some box-pointer
diagrams illustrating the issue, I think.

Kai

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2004-01-28  8:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2004-01-28  8:05 ` Kai Grossjohann

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.