How to kill the content of a list instead of the list itself?
Subject: How to kill the content of a list instead of the list itself?
From: Richard Fateman
Date: Wed, 29 Dec 2010 07:06:47 -0800
On 12/29/2010 6:20 AM, Stefano Ferri wrote:
>
> I think you have to take into account, that the symbols evaluate to
> their numerical value.
>
>
> Thank you, maybe I've made a bit of confusion about this point... But
> there is still an issue: if a, b and c are contained in an unnamed
> list [a, b, c] they can be killed by apply(kill,'[a,b,c]), and this is
> clear. The problem comes when the list [a,b,c] is assigned to a variable:
>
> mylist : [a,b,c]
>
> The only solution I've found is this: mylist must either be defined
> before assigning a value to a, b and c, or defined as
>
> mylist : '[a, b, c]
>
> then apply(kill, mylist) works fine.
First of all, if you do this: a:1, b:2, c:3
then mylist:[a,b,c] does not have any of the symbols a,b,c in it.
All it has is [1,2,3].
Kill is one of the few commands that evaluates its arguments in a
different fashion: it doesn't evaluate them.
That means that kill(a) does not evaluate a to 1, and try to kill 1.
It just uses the name.
My suggestion is that if you anticipate re-using certain names, you
insert in your program the command
kill(a,b,c); before any use of a,b,c.
in fact, it is a good idea, if you repeatedly are loading and testing a
"batch" file
that the first line be something like
kill(program1, program2, variable1, variable2, ....) /* clear old
version of everything out of memory */