clearing shared variables programatically

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

clearing shared variables programatically

Gary Peterson-2
Hello All,
 
Is it possible given a set of classes with known shared variable name(s) for each, to run through those classes and clear the shared variable (setters not available)?
 
    behavior sharedVarNamed: 'nm' put: nil?
 
    Shared vars are a bit different than class vars, I think, so maybe this is not possible.
 
Thank you,
 
Gary P
 
 

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: clearing shared variables programatically

Karsten Kusche
You can send #initialize to a binding like so:

#{YourClass.SharedVariable} initialize.

To initialize all shared variables of a class, you can use:

 aClass asNameSpace bindingReferences do: #initialize.

Kind Regards
Karsten


-- 
Karsten Kusche - Dipl. Inf. (FH) - [hidden email]
Georg Heeg eK - Köthen
Handelsregister: Amtsgericht Dortmund A 12812 

Am Mittwoch, 9. Oktober 2013 um 11:20 schrieb Gary Peterson:

Hello All,
 
Is it possible given a set of classes with known shared variable name(s) for each, to run through those classes and clear the shared variable (setters not available)?
 
    behavior sharedVarNamed: 'nm' put: nil?
 
    Shared vars are a bit different than class vars, I think, so maybe this is not possible.
 
Thank you,
 
Gary P
 
 
_______________________________________________
vwnc mailing list


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: clearing shared variables programatically

Steven Kelly

I’m not sure Karsten’s code does what you want: #initialize will run the initializer, if there is one, or be a no-op if not. Initializers almost never set a value to nil, since that is the default without an initializer, so you’d be unlikely to get the nil value you asked for in your question.

 

If you want to nil all the values, do:

 

SystemUtils modifySystem:

     [[Graph

          localNamesAndBindingsDo:  [:n :cvb | cvb setValue: nil]]

               on: ConstantBindingModificationError

               do: [:ex| ex resume]].

 

This will handle all the shared variables defined in this class itself – recursing to superclasses is kind of dangerous. Note the need to do modifySystem (I think) and to handle the case where the shared var has constant: true – ignore the error and nil it anyway.

 

All the best,

Steve

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Karsten Kusche
Sent: Wednesday, October 9, 2013 12:36 PM
To: Gary Peterson
Cc: [hidden email]
Subject: Re: [vwnc] clearing shared variables programatically

 

You can send #initialize to a binding like so:

 

#{YourClass.SharedVariable} initialize.

 

To initialize all shared variables of a class, you can use:

 

 aClass asNameSpace bindingReferences do: #initialize.

 

Kind Regards

Karsten

 

 

-- 

Karsten Kusche - Dipl. Inf. (FH) - [hidden email]

Georg Heeg eK - Köthen

Handelsregister: Amtsgericht Dortmund A 12812 

 

Am Mittwoch, 9. Oktober 2013 um 11:20 schrieb Gary Peterson:

Hello All,

 

Is it possible given a set of classes with known shared variable name(s) for each, to run through those classes and clear the shared variable (setters not available)?

 

    behavior sharedVarNamed: 'nm' put: nil?

 

    Shared vars are a bit different than class vars, I think, so maybe this is not possible.

 

Thank you,

 

Gary P

 

 

_______________________________________________

vwnc mailing list

 


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc