On Wed, 25 Sep 2013, Allin Cottrell wrote:
For some time now hansl has had three string-handling commands that
are C-like in their syntax, namely printf, sprintf and sscanf. As we
move towards gretl 2.0 (not immediately imminent; I expect at least
a couple more 1.9.N releases first),
At the very very least! :)
I'd like to rationalize these.
Excellent idea.
At present printf and sprintf are available in command form only,
while sscanf has been both a command and a function for over two
years, with the command being deprecated in favour of the function
since gretl 1.9.4 (2011-02-24). In today's CVS I finally removed the
sscanf command so that only the function remains.
First I'll say what I'd like to do, then I'll offer a rationale.
Proposal: Make both printf and sprintf into functions, deprecate the
commands of the same name, and eventually (by 2.0) remove the
commands.
[an extremely lucid series of reasons follow...]
sscanf - ok (besides, it's gone already)
sprintf - ok
printf - I'm a bit hesitant. As Sven said, this is almost certain to break
ALL existing hansl code. Of course, the argument goes both ways. If it has
to be done, the sooner the better.
*Perhaps* the right sequence of steps, if we want to minimise the fallout
is:
- introduce, as an experimental feature, the printf function asap, and
start using it internally as soon as possible (for example, in the sample
scripts, or in addons)
- introduce the new tokenizer supporting the printf command (of course,
provided it isn't to difficult to fit existing syntax into it; Allin?)
- provide some way (the more the better), to sanitize existing scripts:
the equivalent to the python gadget Sven was referring to. This shouldn't
be too hard to do once the tokenizer is proven and robust. It could be a
stand-alone app, or even, maybe, an online thing: you upload the
"printf-as-a-command" inp/gfn file(s) and download the sanitized
"printf-as-a-function" corresponding file(s). Before you say it's
overkill, an infrastructure like this would make it viable to think of
even bolder changes for 2.0.
- make the output from the printf command deliberately annoying; for
example, by printing a big "DEPRECATED" before and after
- stop supporting printf as a command at 2.0
Related: if printf were to become a function in hansl, what if
anything should it return? The C function returns the number of
characters printed. We could probably arrange that if anyone thinks
it's useful, otherwise it could return 0 on success, non-zero if
anything went wrong, or it could be a "void" function that doesn't
give a return value.
If we have the choice, I'd go the C way, if only for compatibility (with
Matlab/octave "fprintf" too). Or maybe, like Ox's "print", the
number of
arguments.
-------------------------------------------------------
Riccardo (Jack) Lucchetti
Dipartimento di Scienze Economiche e Sociali (DiSES)
Università Politecnica delle Marche
(formerly known as Università di Ancona)
r.lucchetti(a)univpm.it
http://www2.econ.univpm.it/servizi/hpp/lucchetti
-------------------------------------------------------