Ralf Hemmecke wrote:
>
> I would like the following function to return a function that I can feed
> into a stream: () -> R -> Stream R function and whose resulting stream
> is supposed to be fed into a series function to generate a Laurent series.
>
> qPochhammerCoefficients(a: P, q: P): () -> R == (): R +->
> n: N := 0
> p: P := 1 - a
> m: P := 1
> d: N := degree a
> degb: N := degree q
> qCoefficient(): R ==
> k := n
> dbgPrint("xk=", k)
> n := n+1
> k < d => [k, coefficient(p, k)]$R
> m := m*q
> d := d+degb
> p := p*(1-m)
> [k, coefficient(p, k)]
> qCoefficient
>
> Compiles fine in the respective package context. The only problem is, it
> doesn't work.
>
> When I call it, it leads to
>
> ...
> [xk=,NIL]
>
> >> System error:
> Argument X is not a NUMBER: NIL
>
> Well, OK, there is a problem with the n not being recognized as the
> variable n from outside the qCoefficient function.
...
> But what is the corresponding declaration in SPAD?
>
> Is there any other way to get the value of the outside variables.
Currently assignment to variables from outer context is not
supported. You can get equivalent effect by writing:
qPochhammerCoefficients(a: P, q: P): () -> R == (): R +->
nn := ref(0)$Reference(N)
....
qCoefficient(): R ==
k := deref(nn)
setelt!(nn, k + 1)
....
So for each variable that is assigned to one needs to create
a reference and use 'deref' and 'setelt!'. To support
assignment compiler needs to automatially perform such
transformation.
--
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.