. .


Create a Block from a String

May 5, 2010 14:20:01.000

I was asked how to store a block from a string this morning, and store the result in an input field. It's actually pretty simple:

string := '[:a | a + 1]'.
block := Compiler evaluate: string.
block value: 10

Now, if you put that behind an input field in a UI, you would want to be extremely careful - you wouldn't want someone typing, say,

[Object := nil].

and just executing the result at some point. To go all Spiderman, "With Great Power Comes Great Responsibility" :)

Technorati Tags:

posted by James Robertson

 Share Tweet This