Smalltalk in Lively
This world demonstrates how Smalltalk code can be evaluated in Lively by compiling it to JavaScript code which is then executed. To try it out select expressions to the right and press CMD+d for evaluating or Cmd+p for printing those Smalltalk expressions. The smaller workspace at the bottom will show the compiled JS code. If you want to know how this is implemented see the OMeta grammar that is used for translating Smalltalk expressions into AST nodes and the very simple ST-JS printer.
ModulePart
X
M

lively.SmalltalkParser
browse
load now
is loaded
Smalltalk workspace
X

Menu
"simple code"
1 + 2.
"simple collection stuff"
#{1. 2. 3. 4. 5.} collect: [:i | i * 2].
"making the world a bit brighter..."
world := ((lively at: 'morphic') at: 'World') current.
world setFill: (Color r: 255 g: 0 b: 0).
"Ascii art with a block"
f := [:x :y | (x + '=' times: y) + x ].
f value: '-' value: 25.
"How warm is it in Palo Alto? (Featuring a block as well, for showing off...)"
extractTemp := [:json | | getter temp |
getter := Global path: 'query.results.channel.item.condition.temp'.
temp := getter get: json.
world inform: ('In ' + loc + ' are ' + temp + ' Fahrenheit').].
loc := 'Palo Alto, CA'.
url := Strings for: 'https://query.yahooapis.com/v1/public/yql?q=%s&format=%s&env=%s'
m: 'select * from weather.forecast where woeid in (select woeid from geo.places(1) where text="' + loc + '")'
a: 'json'
t: 'store://datatables.org/alltableswithkeys'.
(WebResource create: (Global encodeURI: url)) beAsync get withJSONWhenDone: extractTemp.
"make the morphs go round!"
world getSubmorphs forEach: [:morph |
morph
at: 'velocity' put: (Global p: 20 t: 20) random;
at: 'angularVelocity' put: 0.1 * Math random;
start: 100 Stepping: 'stepAndBounce'].
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Compiled JS code
X
M