Ralf Hemmecke wrote:
>
> Can you translate this little function for me?
>
mathprintWithNumber(x : OutputForm) : Void ==
ioHook('startAlgebraOutput)$Lisp
x:= outputTran(x)$Lisp
ind : SExpression := _$IOindex$Lisp
x :=
integer?(ind) => elt('EQUATNUM, integer(ind), x)
x
maprin(x)$Lisp
ioHook('endOfAlgebraOutput)$Lisp
> In particular, I'd be interested in how to access $IOindex. The rest I
> can probably do.
Just escape '$' in the name.
> This here is probably a bit more difficult.
>
> print(x,domain) ==
> dom:= devaluate domain
> $InteractiveMode: local:= true
> $dontDisplayEquatnum: local:= true
> output(x,dom)
>
> since any use of these local variables affect the behaviour of
> output(...), but is not set globally. I don't yet have a good idea how
> to mimick that except to add these local values as new parameters of the
> "output" function.
This one is tricky because Spad do not have dynamic variables.
Most of time extra parameters seem to be best solution.
But if needed we can handle that.
One way is to have boot function like:
do_with_modes(f, x, dom) ==
$InteractiveMode: local:= true
$dontDisplayEquatnum: local:= true
SPADCALL(x, dom, f)
and write
print1(x : OutputForm, dom : SExpression) : Void ==
output(x, dom)$Lisp
print(x : OutputForm, domain : Type) : Void ==
dom : SExpression := devaluate(domain)$Lisp
do_with_modes(print1, x, dom)$Lisp
Once everything is in Spad we can turn variables into
Spad variables and write:
print(x : OutputForm, domain : Type) : Void ==
dom : SExpression := devaluate(domain)
old_dontDisplayEquatnum := dontDisplayEquatnum
old_InteractiveMode
try
output(x, dom)
finally
dontDisplayEquatnum := old_dontDisplayEquatnum
InteractiveMode := old_InteractiveMode
The point of 'try' ... 'finally' construct is that even
in case of error/exception the code to restore old values
still will be run.
Or we can add new construct to Spad to have dynamic
variables. With Lisp backend we could just add appropriate
Lisp declaration. In other backends, the backend would
have to synthetize code like the second variant (btw.
at low level Lisp compiler is doing the same).
> Actually, in a first approach I simply wanted to create a package that
> has in it's add body all the functions of i-output.spad and they would
> simply be defined by a $Lisp call to the respective code from
> i-output.boot. I.e, i would define
>
> SPADoutputTran(x: OutputForm): OutputForm ==
> mathPrint(x)$Lisp pretend OutputForm
>
> and then little by little replace all the lisp calls.
>
> Question: would I have to use another name for the spad function or can
> it be identical to the boot function name? I.e. can I safely drop the
> SPAD prefix in the above snippet?
There is no conflict between Spad and Lisp name, so drop the
prefix.
--
Waldek Hebisch
[email protected]
--
You received this message because you are subscribed to the Google Groups
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.