emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: O(N^2) behavior in LOOP


From: Geoff Gole
Subject: Re: O(N^2) behavior in LOOP
Date: Sun, 30 May 2010 06:35:26 +0800

For what it's worth, the elisp and SBCL implementations of LOOP behave
differently when the last cdr of the loop is assigned to.

; elisp
(loop for i from 1 to 3
      collecting i into x
      collecting (progn (setf (cdr (last x)) (list 'foo)) 1) into x
      finally (return x))
(1 foo 1 2 foo 1 3 foo 1)

; SBCL
(loop for i from 1 to 3
      collecting i into x
      collecting (progn (setf (cdr (last x)) (list 'foo)) 1) into x
      finally (return x))
(1 1 2 1 3 1)

The SBCL macro emits much more efficient code, but I think it's wrong.
Not that LOOP is a particuarly well defined thing to judge correctness
against.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]