Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Lisp > Re: delete comm...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 38 of 64 Topic 12469 of 13603
Post > Topic >>

Re: delete command weirdness

by pjb@[EMAIL PROTECTED] (Pascal J. Bourguignon) May 15, 2008 at 12:16 PM

Barry Margolin <barmar@[EMAIL PROTECTED]
> writes:

> In article <7cod79135p.fsf@[EMAIL PROTECTED]
>,
>  pjb@[EMAIL PROTECTED]
 (Pascal J. Bourguignon) wrote:
>
>> Mark Wooding <mdw@[EMAIL PROTECTED]
> writes:
>> > Unfortunately there's no part of a cons cell to hack that will make
it
>> > look like NIL. 
>> 
>> (defun make-it-look-like-nil (cons) 
>>     (rplaca cons nil)
>>     (rplacd cons nil)
>>     cons)
>> 
>> (let ((cons (cons 1 2)))
>>    (print (and (eq (car 'nil) (car cons))
>>                (eq (cdr 'nil) (cdr cons))))
>>    (make-it-look-like-nil cons)
>>    (print (and (eq (car 'nil) (car cons))
>>                (eq (cdr 'nil) (cdr cons)))))
>> 
>> prints:
>> 
>> NIL 
>> T 
>> 
>> 
>> Therefore:
>> 
>> (defun look-like-nil-p (object)
>>    (ignore-errors   
>>       (and (eq (car 'nil) (car object))
>>            (eq (cdr 'nil) (cdr object)))))
>> 
>> ;-)
>
> Question: How many legs does a person have, if you call an arm a leg?
> Answer: 2 -- calling an arm a leg doesn't make it a leg.

Yes, that's the difference between making a cons cell look like nil,
and making a cons cell become the symbol nil.

>> > As others have mentioned, the purpose of DELETE is to be fast, not to
>> > mutate your list in some carefully described way.  
>> 
>> I don't think that "being fast" is any criterion for DELETE.  It may
>> help to remeber that DELETE works also on vectors (including strings).
>> 
>> In anycase, it will always be O(length(seq)) in time.  What we can do
>> is to make it O(1) in _space_ vs. O(length(seq)) for REMOVE.
>
> REMOVE on a vector has to copy the entire vector (except the removed 
> elements).  DELETE only has to copy starting from the first match.  So 
> while they're both O(length(vector)), DELETE will do fewer copies unless

> you're deleting the first element.  Also, since DELETE is simply 
> ****fting elements within the same array, it should have excellent 
> locality, hence fewer cache misses than REMOVE, which must copy between 
> arrays that are likely to be far apart in memory.
>
> An interesting point about REMOVE on a list is that the result is 
> permitted to share the unmodified tail (i.e. everything after the last 
> match) with the original.  But in order to do this, I think you need to 
> make two p***** -- first you have to search for the last match, then you

> have to copy everything (except the matching elements) leading up to it.
 
> Still O(n), but the coefficient is doubled -- O() notation doesn't tell 
> all.

True, the constants are usually what matter.

-- 
__Pascal Bourguignon__
 




 64 Posts in Topic:
delete command weirdness
Nathaniel Calloway <nt  2008-05-12 22:06:22 
Re: delete command weirdness
christopher.jay.jones@[EM  2008-05-12 20:18:16 
Re: delete command weirdness
vanekl <vanek@[EMAIL P  2008-05-12 20:30:24 
Re: delete command weirdness
Ken Tilton <kennytilto  2008-05-12 23:43:31 
Re: delete command weirdness
Nathaniel Calloway <nt  2008-05-13 01:18:20 
Re: delete command weirdness
Barry Margolin <barmar  2008-05-13 01:37:14 
Re: delete command weirdness
Barry Margolin <barmar  2008-05-13 01:42:59 
Re: delete command weirdness
Nathaniel Calloway <nt  2008-05-13 01:57:29 
Re: delete command weirdness
Peter Hildebrandt <pet  2008-05-13 09:51:03 
Re: delete command weirdness
usenet2.3.CalRobert@[EMAI  2008-05-13 20:59:47 
Re: delete command weirdness
usenet2.3.CalRobert@[EMAI  2008-05-13 19:06:55 
Re: delete command weirdness
Nathaniel Calloway <nt  2008-05-13 01:29:49 
Re: delete command weirdness
pjb@[EMAIL PROTECTED] (P  2008-05-13 15:50:36 
Re: delete command weirdness
Paul Donnelly <paul-do  2008-05-13 01:49:29 
Re: delete command weirdness
Ken Tilton <kennytilto  2008-05-13 09:50:31 
Re: delete command weirdness
Nathaniel Calloway <nt  2008-05-13 12:01:12 
Re: delete command weirdness
Rainer Joswig <joswig@  2008-05-13 18:22:44 
Re: delete command weirdness
Peter Hildebrandt <pet  2008-05-13 18:28:33 
Re: delete command weirdness
Ken Tilton <kennytilto  2008-05-13 13:35:10 
Re: delete command weirdness
Nathaniel Calloway <nt  2008-05-13 13:58:57 
Re: delete command weirdness
pjb@[EMAIL PROTECTED] (P  2008-05-14 12:21:22 
Re: delete command weirdness
Ken Tilton <kennytilto  2008-05-13 12:32:23 
Re: delete command weirdness
Geoffrey Summerhayes <  2008-05-13 01:06:51 
Re: delete command weirdness
Tomas Zellerin <zeller  2008-05-13 07:35:01 
Re: delete command weirdness
Peter Hildebrandt <pet  2008-05-13 17:58:20 
Re: delete command weirdness
David Crawford <crawfo  2008-05-13 09:16:36 
Re: delete command weirdness
kodifik@[EMAIL PROTECTED]  2008-05-13 09:53:06 
Re: delete command weirdness
Rainer Joswig <joswig@  2008-05-13 21:09:39 
Re: delete command weirdness
Kent M Pitman <pitman@  2008-05-13 15:45:57 
Re: delete command weirdness
Matthias Benkard <mulk  2008-05-13 10:38:56 
Re: delete command weirdness
Matthias Benkard <mulk  2008-05-13 10:42:29 
Re: delete command weirdness
Matthias Benkard <mulk  2008-05-13 11:14:46 
Re: delete command weirdness
Barry Margolin <barmar  2008-05-14 00:06:12 
Re: delete command weirdness
danb <sogwaldan@[EMAIL  2008-05-13 13:51:59 
Re: delete command weirdness
Mark Wooding <mdw@[EMA  2008-05-14 11:50:12 
Re: delete command weirdness
pjb@[EMAIL PROTECTED] (P  2008-05-14 14:27:46 
Re: delete command weirdness
Barry Margolin <barmar  2008-05-14 17:01:36 
Re: delete command weirdness
pjb@[EMAIL PROTECTED] (P  2008-05-15 12:16:09 
Re: delete command weirdness
tar@[EMAIL PROTECTED] (T  2008-05-14 14:23:02 
Re: delete command weirdness
Don Geddis <don@[EMAIL  2008-05-14 10:21:20 
Re: delete command weirdness
pjb@[EMAIL PROTECTED] (P  2008-05-15 12:28:05 
Re: delete command weirdness
Kent M Pitman <pitman@  2008-05-15 19:18:21 
Re: delete command weirdness
pjb@[EMAIL PROTECTED] (P  2008-05-16 09:45:07 
Re: delete command weirdness
tar@[EMAIL PROTECTED] (T  2008-05-16 09:43:25 
Re: delete command weirdness
tar@[EMAIL PROTECTED] (T  2008-05-15 09:14:35 
Re: delete command weirdness
Kent M Pitman <pitman@  2008-05-15 19:20:58 
Re: delete command weirdness
Don Geddis <don@[EMAIL  2008-05-15 13:37:16 
Re: delete command weirdness
Lars Brinkhoff <lars.s  2008-05-17 09:22:21 
Re: delete command weirdness
"Steven M. Haflich&q  2008-05-12 22:06:07 
Re: delete command weirdness
Nathaniel Calloway <nt  2008-05-13 01:43:34 
Re: delete command weirdness
Kent M Pitman <pitman@  2008-05-13 05:42:39 
Re: delete command weirdness
usenet2.3.CalRobert@[EMAI  2008-05-13 19:42:57 
Re: delete command weirdness
Kent M Pitman <pitman@  2008-05-14 00:54:58 
Re: delete command weirdness
kodifik@[EMAIL PROTECTED]  2008-05-13 05:48:34 
Re: delete command weirdness
Leandro Rios <leandrop  2008-05-13 10:03:12 
Re: delete command weirdness
pjb@[EMAIL PROTECTED] (P  2008-05-13 15:56:28 
Re: delete command weirdness
Leandro Rios <leandrop  2008-05-13 11:07:01 
Re: delete command weirdness
Kent M Pitman <pitman@  2008-05-13 15:35:05 
Re: delete command weirdness
kodifik@[EMAIL PROTECTED]  2008-05-13 07:13:40 
Re: delete command weirdness
rpw3@[EMAIL PROTECTED] (  2008-05-13 23:04:47 
Re: delete command weirdness
danb <sogwaldan@[EMAIL  2008-05-12 22:39:32 
Re: delete command weirdness
Kent M Pitman <pitman@  2008-05-13 06:27:32 
Re: delete command weirdness
danb <sogwaldan@[EMAIL  2008-05-13 04:10:36 
Re: delete command weirdness
tar@[EMAIL PROTECTED] (T  2008-05-13 15:53:53 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Oct 11 2:22:02 CDT 2008.