How can I remove all the items of a list?

Guest
Hello all,
By using the SKILL function remd, I can remove some items of a
list. But how can I remove all the items of a list? In other words, how
can I make a list be empty?
Thanks.
 
Tom_Ding@hotmail.com wrote:
Hello all,
By using the SKILL function remd, I can remove some items of a
list. But how can I remove all the items of a list? In other words, how
can I make a list be empty?
Thanks.
Do you want to destructively make a list empty? Or just set a
variable to an empty list?
You could do something like the following:

(while (car some-list)
(remd (car some-list) some-list))

But if you just want to replace some-list with an empty list
you can use (some-list = nil)

What do you want to happen to other references to parts of
the list? for example

x = (list 1 2 3 4 5)
y = (cdr x)
z = (cons 0 x)

Note that y points to the list ( 2 3 4 5), but the same one
that (cdr x) points to. So if you do not care that y still
points to ( 2 3 4 5) you can do something more efficient
to x. This y unchanged, but sets z to the list ( 0)

(rplacd x nil)
(remd (car x) x)

-jim
 

Welcome to EDABoard.com

Sponsor

Back
Top