how to remove a variable in SKILL

K

kamal

Guest
hi ,

I am new to the cadence environment.
I need to remove a variable in my code
eg : test= 1

is there any function say --> foo(test)
so that after this , if i type test on the skill window, it should say
"undefined variable test"

though at present i am doing it by assigning "test = nil" , but is
there any way we can remove this variable completely , like we have
"delete" in c++.

Thanks & Regards
Kamal
 
You can declare 'test' always as local variable
in your function with the 'let' statement.


procedure( foo( )
let( ( test )

test = 1

)
)

the you do

foo()
=> 1

*Error* toplevel: undefined variable - test


or use 'unbound

test = 1

test
=> 1

test = 'unbound

test
=
*Error* toplevel: undefined variable - test


Bernd


kamal wrote:
hi ,

I am new to the cadence environment.
I need to remove a variable in my code
eg : test= 1

is there any function say --> foo(test)
so that after this , if i type test on the skill window, it should say
"undefined variable test"

though at present i am doing it by assigning "test = nil" , but is
there any way we can remove this variable completely , like we have
"delete" in c++.

Thanks & Regards
Kamal
 
More elegant

test = 1
=> 1

setq( test 'unbound )

test
*Error* toplevel: undefined variable - test


Bernd


Bernd Fischer > wrote:
You can declare 'test' always as local variable
in your function with the 'let' statement.


procedure( foo( )
let( ( test )

test = 1

)
)

the you do

foo()
=> 1

test
=
*Error* toplevel: undefined variable - test


or use 'unbound

test = 1

test
=> 1

test = 'unbound

test
=
*Error* toplevel: undefined variable - test


Bernd


kamal wrote:

hi ,

I am new to the cadence environment.
I need to remove a variable in my code
eg : test= 1

is there any function say --> foo(test)
so that after this , if i type test on the skill window, it should say
"undefined variable test"

though at present i am doing it by assigning "test = nil" , but is
there any way we can remove this variable completely , like we have
"delete" in c++.
Thanks & Regards
Kamal
 
Hi Karnal, what do you mean by "variable". There is no way
in SKILL to destroy a symbol once it has been created. However
variables automatically go out of scope when the let which bound them
finishes.

(let (a b c)
;; here a b and c are in scope
a=1
b=a
(foo c=a+b))


;; now a b and c are no longer in scope and no longer accessable

does this help?
 
However, if you mean you want the data which a variable references
to be available for garbage collection, you simply have to dereference
it.
I"m not sure what "Delete" does in c++, but it sounds like it does
something similar.

(let ((a (list 1 2 3 3 4 5 6 7 8)))
;; here a points to a newly allocated list of length 8
a = nil
;; now there is no longer a reference to the list so it will be
;; automatically deallocated by the system.
)

(let ((a (list 1 2 3 3 4 5 6 7 8))
b)
;; here a points to a newly allocated list of length 8
b = a
;; now there are two references to the list
a=nil
;; now there is only one reference to the list
)
;; now b is no longer in scope so there is no longer a reference
;; to the list and it will automatically be deallocated.
 
Hi Jim,

Just for my personal interest, have you read my
reply on this?
Did I misunderstood the something when
setting the variable to unbound?

test = 1
=> 1

setq( test 'unbound )

test
*Error* toplevel: undefined variable - test


Bernd


Jimka wrote:
Hi Karnal, what do you mean by "variable". There is no way
in SKILL to destroy a symbol once it has been created. However
variables automatically go out of scope when the let which bound them
finishes.

(let (a b c)
;; here a b and c are in scope
a=1
b=a
(foo c=a+b))


;; now a b and c are no longer in scope and no longer accessable

does this help?
 
hi bernd, yes setting a variable to unbound is possible, but it
is something that is not normally done within a program. variables
automatically become unbound when they go out of scope.
yes setting to unbound is something you might do when you
are debugging.

It was not clear to me however, what the OP really wanted to do
by "deleting" a variable.
 
hi Bernd,

Thanks for your help.

Using
test = 'unbound
solved my problem .

Thanks once again
kamal
 
hi Jim,
thanks for the help.
Actually the code that I was working on had some global variable and I
wanted to remove them
from the memory so I was looking for some "delete" kind of option.
However now I have defined them as let () , and this has to a large
extent solved my problem.

kamal
 

Welcome to EDABoard.com

Sponsor

Back
Top