Karim Belabas on Thu, 20 Nov 1997 15:30:39 +0100


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

Re: From the 2.0.alpha Tutorial (1)


WARNING: This is a LONG answer (containing some supposedly useful tips
though).

> Gerhard Niklasch <nikl@pchelwig1.mathematik.tu-muenchen.de> wrote:

> Just running the Tutorial through its paces with 2.0.alpha.  Or vice versa.
> [1]--- Section 1, `Warning 6)':
> The syntax for changing the real output format is
> 	default(format, "e0.50")
> (it doesn't work without the quotes).

Yep, thanks for the tutorial bugs. The second argument of default is in
"string context". That is, everything is expanded as a normal GP expression
(in particular strings are left alone, they expand to themselves), then
converted to a string. Without the quotes, e0.50 looks for the member
function "50" (with little success...) and tries to apply it to the structure
"e0".

NOTE (Tip of the Week...): By the way, remember in string context, everything
gets concatenated as a single string. The rationale is that on can easily
generate strings at run-time without cumbersome concat() operations (besides,
it was introduced before strings existed...). For instance

default(logfile, "log." extern("mydate") "." val)

would work (that's an imaginary example...). Where:

* mydate is an external shell script, for instance :

#!/bin/sh
a=`date`; echo \"$a\" | sed 's/ /./g'

that just outputs the date surrounded by quotes (a string for GP), with
internal spaces replaced by dots for legibility's sake (that's a very
stupid example, normally one would use the +format parameter of date to
cancel useless fields).

* val is some important numerical parameter that you set somewhere in the
session.

For instance:
(14:48) gp > val = 100
%1 = 100

(14:49) gp > default(logfile, "log." val "::" extern("mydate"))
%2 = "Thu.Nov.20.14:57:54.MET.1997"
   logfile = "log.100::Thu.Nov.20.14:57:54.MET.1997"

Which sets the logfile to this string from outer space...

The %2 comes from the fact that extern() executes a system command and feeds
the result to GP, so the output of mydate went in the history (read()
has the same behaviour).

Ok, on to the next one...

> [3]--- Still Section 3, quadratic numbers, page 8:  after

Touche ! Yet Another Bug. This is addressed in my next mail.


> [4]--- Something else I noticed whilst playing:
> 
> default(compatible,0)
> 	resets the real output format (partially: it was "e0.50"
> before I switched from compatible=1 to 0, afterwards it was "e0.28"),
> which I think it shouldn't do,

I'm not able to reproduce this. Can you send a minimal example ?

> \k
> 	resets several defaults and doesn't reinitialize them from
> ~/.gprc (or GPRC).  In particular, all colors get set to -1, the
> prompt is set to "? ", and all aliases are lost.  The latter is
> arguably correct insofar as we don't remember any additional aliases
> generated during the preceding part of the session, but it's a shame
> that the aliases read at startup are also gone.  Perhaps \k now needs
> an optional numeric argument so that users can decide how much of their
> default customizations it should restore?  (0 -- effectively reread
> ~/.gprc which, if there is an aliases file, would read that back in,
> and I think this should be the default.  1 -- erase everything to
> `factory settings'...)

This metacommand's behaviour is weirder than that: it does not kill
variables... A brief history:

* version 1.39.15 and before: variables can not be killed completely
so that y=1; kill(y); y()=... yields an error (y is still remembered as a
variable). Note: there never was a problem the other way round, you could get
rid of functions and turn them into variables. So \k provided a reliable way
to get rid of all variables. As you got a SEGV as a bonus if a stack doubling
occurred, this was not strictly equivalent to exiting and coming back in.

* version 2.0.alpha: variables can be completely killed, although if you kill
too many (about 16000...), you run into problems since they are not recycled
(something like "not enough variables"). You don't even get a SEGV with
\k, so it becomes totally useless. 

  I decided somewhat arbitrarily to have it give "factory settings" (gprc is
not read) AND keep the variables values (you could already get "factory
settings" by running gp -f). I still find it completely useless, but at least
it provides some new functionnality (and nobody in the team objected when I
did it, so it was kept that way...).

  As there will soon be commands to save and restore an entire session, this
will become pointless as well. It's of course trivial to add a parameter to
it. What do you people think would be useful (I mean, something that you
would actually use...) ?
--
Karim Belabas                          e-mail:
Max-Planck-Institut fuer Mathematik       karim@mpim-bonn.mpg.de
Gottfried-Claren-Str. 26               tel:
53225 Bonn (Germany)                      (00 49 228) 402-245