| Author |
Message |
Guest
|
Posted:
Tue Nov 16, 2004 11:50 am Post subject:
How can I remove all the items of a list? |
|
|
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.
|
|
| Back to top |
|
 |
Jim Newton
Guest
|
Posted:
Tue Nov 16, 2004 12:10 pm Post subject:
Re: How can I remove all the items of a list? |
|
|
Tom_Ding@hotmail.com wrote:
| Quote: | 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 |
|
| Back to top |
|
 |
Guest
|
Posted:
Tue Nov 16, 2004 1:02 pm Post subject:
Re: How can I remove all the items of a list? |
|
|
Oh! I see.
Thanks a lot!
|
|
| Back to top |
|
 |
|
|
|
|