Re: popold
- From: Edi Weitz <spamtrap@xxxxxxxxxx>
- Date: Thu, 05 Jan 2006 15:15:50 +0100
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")
.
- References:
- popold
- From: verec
- popold
- Prev by Date: popold
- Next by Date: Re: What is the main advantage of macros over functions?
- Previous by thread: popold
- Next by thread: Re: popold
- Index(es):
Relevant Pages
|