[Ometa] Logo Demo
Alessandro Warth
alexwarth at gmail.com
Wed Dec 30 18:02:07 PST 2009
Hi Chris,
I'm writing this on my phone, so I'll have to be brief...
When you highlight some code and then press the "do it" button in the
OMeta/JS Wiki, the highlighted code doesn't run directly. It is passed to
the translateCode function, which is in charge of translating your code into
JS code that is in turn passed to the eval function. This is a simple way to
allow programmers to have control over the language they get to program in.
My Logo example was taking advantage of this. The trick to making it go is
to highlight the grammar and the definition of translateCode (but not the
sample Logo code) and press do-it. At that point, you will have switched the
language that's understood in the workspage to Logo. So now you should be
able to highlight the definition of spiral, and the call, and it will work.
(If you "do-it" the entire thing at once, it doesn't work b/c the original
translateCode is used for the whole thing.)
I think that's much nicer than having to put the code in a JS string...
(I don't have a computer handy, but I'm pretty sure that the conclusion of
my dissertation explains the translateCode stuff.)
Ok, that wasn't exactly brief. Happy new year's eve eve! :)
Cheers,
Alex
Sent on the Sprint=AE Now Network from my BlackBerry=AE
On Wed, Dec 30, 2009 at 4:17 PM, Chris Cunnington <brasspen at gmail.com>wrote:
> Hi Alex,
>
> The bottom of the Logo Demo says:
>
> smiley =3D new Turtle()
> translateCode =3D function(code) { smiley.eval(code); return "undefined" }
>
> to spiral :size :angle
> if :size < 100 [
> fd :size
> rt :angle
> spiral :size + 2 :angle
> ]
> end
>
> spiral 0 89
>
> I don't know what translateCode is for, or how the Logo code gets into the
> "code" variable to be eval'd by smiley.
> So, I adapted the code from your Old OMeta JS example thusly:
>
> smiley =3D new Turtle()
> smiley.eval('
>
> to spiral :size :angle
> if :size < 100 [
> fd :size
> rt :angle
> spiral :size + 2 :angle
> ]
> end
>
> spiral 0 89')
>
> Now I can see how the Logo code gets into smiley to be eval'd. The result
> produces a spiral on the canvas.
> I'm quite pleased with my hack. But I'd like to know how it's supposed to
> work with translateCode.
> How was the Logo code supposed to get into the "code" variable for smiley
> to execute?
>
> Chris
>
> _______________________________________________
> OMeta mailing list
> OMeta at vpri.org
> http://vpri.org/mailman/listinfo/ometa
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://vpri.org/pipermail/ometa/attachments/20091230/bc2f5bd7/attachme=
nt.htm
More information about the OMeta
mailing list