Blocks from strings

Laurence.Rozier at knowledgearchitects.net Laurence.Rozier at knowledgearchitects.net
Tue Dec 30 23:25:01 UTC 2003


>On Monday 29 December 2003 8:28 pm, Nevin Pratt wrote:
>> How do I programmatically create a block from a string?
>> 
>> The block's context would be the method that is creating the block.
If temp vars dot matter, then Ned and Lex have provided examples. Also, you can use something like: 

 
Compiler evaluate: '[myInstanceVar class] value' for: self logged: false


to access the instance variables of the object that's creating the block. 


If you intend for the block's code to access temporary variables declared in the method that created it, Workspace and Debugger provide two different approaches. 

-Laurence
>> 
>> Nevin
>> 
>> 
>> -- 
>> Nevin Pratt
>> Bountiful Baby
>> http://www.bountifulbaby.com
>> (801) 992-3137
>> 
>> 
>
>This is kind of an excerpt from some of my code; you can try it in a 
>Workspace.
>
>	model := nil.	"or set to Browser or Workspace, etc."
>	stream := ReadWriteStream
>				on: (String new: 100).
>	stream nextPutAll: '[ 3 + 4 ]'.	"your code here in brackets"
>	stream reset.
>	(model respondsTo: #doItReceiver)
>		ifTrue: [FakeClassPool adopt: model selectedClass.
>			"Include model pool vars if any"
>			rcvr := model doItReceiver.
>			ctxt := model doItContext]
>		ifFalse: [rcvr := ctxt := nil].
>	result := [rcvr class evaluatorClass new
>				evaluate: stream
>				in: ctxt
>				to: rcvr
>				notifying: self
>				ifFail: [FakeClassPool adopt: nil.
>					^ #failedDoit]]
>				on: OutOfScopeNotification
>				do: [:ex | ex resume: true].
>	FakeClassPool adopt: nil.
>	
>result value
>


More information about the Squeak-dev mailing list