| Bill Allombert on Thu, 22 Jan 2015 20:25:55 +0100 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| Re: Undocumented prototype code "C" in eval() |
On Wed, Jan 21, 2015 at 08:29:44PM +0100, Bill Allombert wrote:
> On Tue, Jan 20, 2015 at 02:41:10PM +0100, Jeroen Demeyer wrote:
> > The function eval() has a code C in the prototype which is not documented:
> >
> > Function: eval
> > Section: polynomials
> > C-Name: geval_gp
> > Prototype: GC
>
> Indeed, it is a private code for the GP compiler.
> This allows the code run through eval() to reference lexical variables
> declared with my() by the caller.
> This is the magic used so that
> my(z=2);eval("z^2")
> works.
>
> The parameter C is a "pack", a data structure describing the list of
> lexical variables. This is used to preseed the GP compiler before
> compiling "z^2" so that z is known.
We have improved the documentation in rev 8fcea79e
It now reads
\subsec{Functions related to the GP evaluator}
The prototype code \kbd{C} instructs the GP compiler to save the current
lexical context (pairs made of a lexical variable name and its value)
in a \kbd{GEN}, called \kbd{pack} in the sequel. This \kbd{pack} can be used
to evaluate expressions in the corresponding lexical context, providing it is
current.
\fun{GEN}{localvars_read_str}{const char *s, GEN pack} evaluate the string $s$
in the lexical context given by \kbd{pack}. Used by \tet{geval_gp} in GP
to implement the behaviour below:
\bprog
? my(z=3);eval("z=z^2");z
%1 = 9
@eprog
Thanks for reporting this issue!
Cheers,
Bill