On Jun 10, 2008, at 10:26 AM, mark richardson wrote:
declare
MyOzCode = "local X=3 in X+X end"
{Browse {Compiler.virtualStringToValue MyOzCode}}
Hi, I can see that working but what if MyOzCode="{Browse 1+2}" for
example - that doesn't work!? I tried using Browser.browse, feeding a
module link first, but that doesn't work either.
There are two problems here. Firstly, Compiler.virtualStringToValue
always expects an expression, not a statement (you can change that
for your own compiler with a compiler switch, see docs). Secondly,
the OPI (the Emacs-based Mozart IDE) already defines a number of
convenient things which are not defined in the bare language and are
gone if you use a bare compiler. For example, there is no keyword
declare anymore. Also, many functors (e.g., Browser) are not linked
and convenient variables or often used functions (e.g., Browse, Map
etc.) are not defined. BTW:
x-oz://system/OPIEnv.ozf exports the full OPI environment as
OPIEnv.full, if you want to add that environment to your custom
compiler.
So, here is a quickly cocked up compiler definition which is similar
to Compiler.virtualStringToValue, but instead supports the full OPI
environment and expects a statement instead of an expression. Note
that this def always creates a new compiler, for your purposes you
will define the compiler only once and then feed strings to this
custom-made compiler engine. Also, not that for simplicity this
definition does not provide any means for stopping or exception
handling. See the orig def of Compiler.virtualStringToValue I send
before for some way to do that.
declare
[OPIEnv] = {Module.link ['x-oz://system/OPIEnv.ozf']}
proc {ExecStatement VS}
E I S
in
E = {New Compiler.engine init()}
I = {New Compiler.interface init(E)}
{E enqueue(mergeEnv(OPIEnv.full))}
{E enqueue(setSwitch(expression false))}
{E enqueue(setSwitch(threadedqueries false))}
{E enqueue(feedVirtualString(VS))}
end
{ExecStatement '{Browse hi}'}
Best
Torsten
--
Torsten Anders
Interdisciplinary Centre for Computer Music Research
University of Plymouth
Office: +44-1752-586227
Private: +44-1752-558917
http://strasheela.sourceforge.net
http://www.torsten-anders.de
_________________________________________________________________________________
mozart-users mailing list
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users