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


|