Karim BELABAS on Mon, 22 Sep 2003 17:40:10 +0200 (MEST)


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: peculiar Set/eval behavior


On Sat, 20 Sep 2003, Bill Allombert wrote:

> On Fri, Sep 19, 2003 at 05:55:04PM +0200, Karim BELABAS wrote:
> > No, it's not proper.
> >
> > Fixed in CVS [ make sure "raw" output format is chosen, not "prettymat" ].
>
> It is my belief that the default(output) should not affect library
> functions, only the way GP output result.
> This mean we should provide alternative of print,etc for prettymat
> format.

The following defaults:

  format, output, realprecision, TeXstyle

affect library functions output. There's a default "global output context"

  pariout_t DFLT_OUTPUT;

for library functions. If one tampers with it (as GP does by modifying the
above), then one expects output convention to change, e.g number of
significant digits printed.

-- All output primitives take an "output context" as argument, which is often
not the global one because

-- All output routines import this general output context, modify (in a local
copy) settings wich they really care about, if needed, and pass the result to
primitives.

So you can both output with arbitrary settings (without touching any global
variable), and set global default settings (modifying the DFLT_OUTPUT
global).

GP does the latter so that all outputs are consistent, esp. for conversion
routines like Set() or Str(), which could be changed to also accept an output
context parameter. IMHO, that's overkill in the current implementations, and
involves modifying all 'set' routines, breaking compatibility.

To change GP's behaviour is trivial: have GP_DATA->fmt point to another
instance of pariout_t, and not to DFLT_OUTPUT. As mentionned above, this
is not worth it unless you intend to rewrite sets first [ e.g. using
hashtables ]

=============================================================================

The problem above was that "canonicalization" of a GEN (to a string, which is
quite inefficient, I know...) wants to depend as little as possible from
global context. And did not enforce it. In particular I had forgotten the
above override in the corresponding function.

My patch (updated a few minutes ago, btw) to GENtoGENstr [ from gtoset ] makes
sure output mode is f_RAW and no extra "beautifying" spaces are added.

Cheers,

    Karim.
-- 
Karim Belabas                     Tel: (+33) (0)1 69 15 57 48
Dép. de Mathématiques, Bât. 425   Fax: (+33) (0)1 69 15 60 19
Université Paris-Sud              http://www.math.u-psud.fr/~belabas/
F-91405 Orsay (France)            http://www.parigp-home.de/  [PARI/GP]