What is correct way to remove a global variable - I get a walkback?

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

What is correct way to remove a global variable - I get a walkback?

TimM-3
If I execute the following code:

Smalltalk at: #TestGlobalForRemoval put: 5.
Smalltalk removeGlobalNamed: #TestGlobalForRemoval


I get a walkback - is this the correct way to remove a global (its a public
method, and #remove: has been overwritten).?


Tim


Reply | Threaded
Open this post in threaded view
|

Re: What is correct way to remove a global variable - I get a walkback?

Ian Bartholomew-20
Tim,

> I get a walkback - is this the correct way to remove a global (its a public
> method, and #remove: has been overwritten).?

What walkback do you get?.  Your code works without error for me unless
I try to remove the global twice, which does cause a not found walkback.

FWIW, I would usually use ....

Smalltalk at: #TestGlobalForRemoval put: 5.
Smalltalk removeKey: #TestGlobalForRemoval ifAbsent: []

I have to admit a complete ignorance about the existence of
#removeGlobalNamed: though :-)

Ian


Reply | Threaded
Open this post in threaded view
|

Re: What is correct way to remove a global variable - I get a walkback?

TimM-3
> What walkback do you get?.  Your code works without error for me unless I
> try to remove the global twice, which does cause a not found walkback.

Hmmm your right - in a clean image its ok. My semi clean image gives a
'VariableBinding does not understand #asSymbol'
and it opens an inspector on the symbol.

It looks like something is registered for #onGlobalRemoved and what it gets
is an association rather than just a key.

I wonder what I have done to cause this?

Tim

20:13:32, 04 November 2005: 'VariableBinding does not understand #asSymbol'
VariableBinding(Object)>>doesNotUnderstand:
SystemDictionary>>at:ifAbsent:
SystemDictionary(Dictionary)>>at:
StsManager>>onSystemGlobalRemoved:
EventMessageSend>>forwardTo:withArguments:
EventMessageSend(MessageSendAbstract)>>valueWithArguments:
[] in MessageSequenceAbstract>>valueWithArguments:
EventMessageSequence>>messagesDo:
EventMessageSequence(MessageSequenceAbstract)>>valueWithArguments:
EventsCollection>>triggerEvent:with:
RefactoringSmalltalkSystem(Object)>>trigger:with:
RefactoringSmalltalkSystem(SmalltalkSystem)>>onGlobalRemoved:
EventMessageSend>>forwardTo:withArguments:
EventMessageSend(MessageSendAbstract)>>valueWithArguments:
[] in MessageSequenceAbstract>>valueWithArguments:
EventMessageSequence>>messagesDo:
EventMessageSequence(MessageSequenceAbstract)>>valueWithArguments:
EventsCollection>>triggerEvent:with:
SystemDictionary(Object)>>trigger:with:
SystemDictionary>>removeKey:ifAbsent:
SystemDictionary(Dictionary)>>removeKey:
SystemDictionary>>removeGlobalNamed:
UndefinedObject>>{unbound}doIt
CompiledExpression>>value:
SmalltalkWorkspace>>evaluateRange:ifFail:debug:
SmalltalkWorkspace>>evaluateItIfFail:debug:
SmalltalkWorkspace>>evaluateItIfFail:
SmalltalkWorkspace>>evaluateIt
Symbol>>forwardTo:
CommandDescription>>performAgainst:
[] in Command>>value
BlockClosure>>ifCurtailed:
BlockClosure>>ensure:
Command>>value
ShellView>>performCommand:
IdeaSpaceShell(Shell)>>performCommand:
CommandQuery>>perform
DelegatingCommandPolicy(CommandPolicy)>>route:
[] in ShellView(View)>>onCommand:
BlockClosure>>ifCurtailed:
BlockClosure>>ensure:
Cursor>>showWhile:
ShellView(View)>>onCommand:
ShellView(View)>>wmCommand:wParam:lParam:
ShellView(View)>>dispatchMessage:wParam:lParam:
[] in InputState>>wndProc:message:wParam:lParam:cookie:
BlockClosure>>ifCurtailed:
ProcessorScheduler>>callback:evaluate:
InputState>>wndProc:message:wParam:lParam:cookie:
ShellView>>translateAccelerator:


Reply | Threaded
Open this post in threaded view
|

Re: What is correct way to remove a global variable - I get a walkback?

Ian Bartholomew-20
Tim,

> It looks like something is registered for #onGlobalRemoved and what it gets
> is an association rather than just a key.

The walkback occurs when you have STS running in the image.  It happens
because the argument Dolphin sends with the #onGlobalRemoved: event is
an Association containing the key and value that are being removed. The
StsManager registers for this message but expects the argument to be
the key, not the key and value, of the global being removed.

Another problem is that the event is sent _after_ the global has been
removed so the method, as it stands, won't work anyway.  Changing it to
the following seems to work.

StsManager>>onSystemGlobalRemoved: globalName
        | global |
        ((global := globalName value) isKindOf: Class)
                ifTrue: [classEditions isNil ifFalse: [classEditions removeKey: global
name ifAbsent: []]]

Ian

NB <disclaimer> I know the above method can be written in a more compact
way, I was just changing the minimum amount needed to get it to work.


Reply | Threaded
Open this post in threaded view
|

Re: What is correct way to remove a global variable - I get a walkback?

TimM-3
Ahh so it wasn't me then...  Do we need to log this one?

Agreed on minimal changes.

tim

"Ian Bartholomew" <[hidden email]> wrote in message
news:[hidden email]...

> Tim,
>
>> It looks like something is registered for #onGlobalRemoved and what it
>> gets is an association rather than just a key.
>
> The walkback occurs when you have STS running in the image.  It happens
> because the argument Dolphin sends with the #onGlobalRemoved: event is an
> Association containing the key and value that are being removed. The
> StsManager registers for this message but expects the argument to be the
> key, not the key and value, of the global being removed.
>
> Another problem is that the event is sent _after_ the global has been
> removed so the method, as it stands, won't work anyway.  Changing it to
> the following seems to work.
>
> StsManager>>onSystemGlobalRemoved: globalName
> | global |
> ((global := globalName value) isKindOf: Class)
> ifTrue: [classEditions isNil ifFalse: [classEditions removeKey: global
> name ifAbsent: []]]
>
> Ian
>
> NB <disclaimer> I know the above method can be written in a more compact
> way, I was just changing the minimum amount needed to get it to work.


Reply | Threaded
Open this post in threaded view
|

Re: What is correct way to remove a global variable - I get a walkback?

TimM-3
> Ahh so it wasn't me then...  Do we need to log this one?

I'll log it anyway as it gives OA some tracability.


Reply | Threaded
Open this post in threaded view
|

Re: What is correct way to remove a global variable - I get a walkback?

Ian Bartholomew-20
Tim,

> I'll log it anyway as it gives OA some tracability.

Thank you

Ian