Evaluating a String as code -djb

Alan Kay Alan.Kay at squeakland.org
Sat Feb 8 22:08:23 UTC 2003

Add this method to string and try it:

  ^Compiler new evaluate: self in: nil to: nil notifying: nil ifFail: nil

'3+4' eval


Check out the comment in Compiler>>evaluate etc., to see what the 
other options are.

I'm very surprised that this method isn't already in Squeak 
somewhere. (But perhaps it's just as  well ...)



At 12:40 PM -0800 2/8/03, Derek Brans wrote:
>Given a string, is there anyway to evaluate its contents as code in 
>the current context?
>Essentially I want to write a function that given a string like this:
>' This is a test of < | foo | foo := self bar. foo upperCase. > to 
>see if it works '
>returns a string like this:
>'This is a test of Something to see if it works'
>Thank you in advance,
>Nerd on a Wire: Web and Information Solutions
>Website Design - Database Systems - Site Hosting
>mailto:info at nerdonawire.com
>For more information, visit http://nerdonawire.com


More information about the Squeak-dev mailing list