Re: popold



On Thu, 5 Jan 2006 13:56:24 +0000, verec <verec@xxxxxxx> wrote:

> 1. if I'm only interested in portable CL, why would I ever consider
> using delete rather than remove since there is no guarantee that the
> target sequence is modified?

DELETE, like other destructive operations, is there because it can be
potentially faster[1] if it operates on large structures. You
can/should use it if you know that the list you're working with is
"yours" and will be thrown away anyway. Otherwise you must not use
it.

But you have to keep in mind that destructive and non-destructive
functions are always used the same way, it's

(setq new-list (remove item old-list))

and it's

(setq new-list (delete item old-list)).

> 3. Regarding the *features* list [...] I've got that feeling that it
> is some kind of "system resource" that is OK to "look but don't
> touch"

Nah, it's OK to modify it but usually you shouldn't remove features
you haven't put there yourself. Many libraries add something to
*FEATURES*.

HTH,
Edi.

[1] Consider this example:

CL-USER 23 > (defun range (n)
(loop for i below n collect i))
RANGE

CL-USER 24 > (compile 'range)
RANGE
NIL
NIL

CL-USER 25 > (defun foo (fn)
(funcall fn 2 (range 1000000))
(values))
FOO

CL-USER 26 > (compile 'foo)
FOO
NIL
NIL

CL-USER 27 > (time (foo #'remove))
Timing the evaluation of (FOO (FUNCTION REMOVE))

user time = 0.570
system time = 0.010
Elapsed time = 0:00:01
Allocation = 11216 bytes standard / 22005555 bytes conses
0 Page faults

CL-USER 28 > (time (foo #'delete))
Timing the evaluation of (FOO (FUNCTION DELETE))

user time = 0.140
system time = 0.010
Elapsed time = 0:00:00
Allocation = 7504 bytes standard / 11004796 bytes conses
0 Page faults

Note that REMOVE /must/ allocate a new list with 1,000,000 elements
while DELETE can re-use the old list and just "uncouple a pointer," so
to say.


--

Lisp is not dead, it just smells funny.

Real email: (replace (subseq "spamtrap@xxxxxxxxxx" 5) "edi")
.



Relevant Pages

  • Re: NIL as :key to ASSOC, INTERSECTION, POSITION, &c.
    ... I wouldn't have thought think that providing NIL as a:key ... (defun foo (&key bar) ... Above you would need to check for each keyword argument ...
    (comp.lang.lisp)
  • Re: Scoping Question
    ... * (setf foo 3) ... Warning: This variable is undefined: ... WARN is an external symbol in the KEYWORD package. ... NIL -- Never declare the variable, ...
    (comp.lang.lisp)
  • When does ADJUST-ARRAY cons?
    ... Here is our test file: ... ;; 0 Page faults ... Elapsed time = 0:00:01 ... (defparameter *line* nil) ...
    (comp.lang.lisp)
  • Re: Why if 0 succeeds in Ruby
    ... Every *comparison* with nil does fail. ... "unless foo" is not a comparison of foo with false, ... His code sample showed what he meant! ...
    (comp.lang.ruby)
  • Re: new block notation
    ... difference easy and clean, the way that it is now. ... irb:036:0> task foo do |t| p t end ...
    (comp.lang.ruby)