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


Computer Aided Design - CAD > Cadence > Re: Deleting an...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 6 Topic 3987 of 4373
Post > Topic >>

Re: Deleting an element

by "S. Badel" <stephane.badel@[EMAIL PROTECTED] > May 6, 2008 at 01:35 PM

Just a few more comments

> you can use the "remove" option:
> for example -
> lst=list(1 2 3 4)
> lst2=remove(3 lst)

note that this'll remove all elements equal to 3, so that
lst=list(1 2 3 2 3)
lst2=remove(3 lst)

will result in lst2='(1 2 2)

> or you can use "remd":
> remd(3 lst)
> 
> now
> 
> lst=(1 2 4)

remd is destructive, i.e. it modifies the list itself (while remove works
on a copy of the list). 
But there's a catch :

lst=list(1 2 3 4)
remd(1 lst)
=> (2 3 4)
lst
=> (1 2 3 4)

remd can not modify where lst is "pointing to", so it can't remove the car
of a list. Therefore it's 
safer to use

  lst=remd(1 lst)


also, be careful with destructive operations ; consider that symbols are
"pointing" to lists, and 
therefore when two symbols are pointing to the same list, modifying one
also affects the other :

lst=list(1 2 3 4)
lst2=lst ;; <= both are pointing to the same list here
remd(2 lst)
=> (1 3 4)
lst2
=> (1 3 4)


one last word : to destructively remove the element at index i in the list
lst,

rplacd(rplacd(nthcdr(i-1 lst) nthcdr(i+1 lst))



Cheers,
Stéphane
 




 6 Posts in Topic:
Deleting an element
nour <nour.laouini@[EM  2008-05-05 08:37:44 
Re: Deleting an element
Riad KACED <riad.kaced  2008-05-05 12:33:38 
Re: Deleting an element
danniel <danniel@[EMAI  2008-05-06 00:26:01 
Re: Deleting an element
"S. Badel" <  2008-05-06 13:35:55 
Re: Deleting an element
"S. Badel" <  2008-05-06 14:38:51 
Re: Deleting an element
Andrew Beckett <andrew  2008-05-08 10:47:21 

Post A Reply:
  Go here to Signup

AddThis Feed Button


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

Contact
tan12V112 Mon Dec 1 13:20:08 CST 2008.