Discussion:
How can I evaluate code stored in string?
(too old to reply)
dmytro starosud
2011-02-19 20:56:11 UTC
Permalink
Hello,

Is there in Smalltalk (GNU Smalltalk is used) something like "eval"
function.
I want to do some kind of following:

str := '2 + 3'.
out := str evaluate. "and out equal 5"

str may contain any valid Smalltalk expressions.

thank you
ZuLuuuuuu
2011-02-20 19:29:22 UTC
Permalink
Post by dmytro starosud
Hello,
Is there in Smalltalk (GNU Smalltalk is used) something like "eval"
function.
str := '2 + 3'.
out := str evaluate. "and out equal 5"
str may contain any valid Smalltalk expressions.
thank you
You can use the Behavior class:

Behavior evaluate: '2 + 3'
dmytro starosud
2011-02-20 19:46:50 UTC
Permalink
Post by ZuLuuuuuu
Behavior evaluate: '2 + 3'
Thank you, very much, it really helps me.

Loading...