On Mon, 18 Dec 2017, Sven Schreiber wrote:
Am 18.12.2017 um 12:50 schrieb Riccardo (Jack) Lucchetti:
> On Mon, 18 Dec 2017, Riccardo (Jack) Lucchetti wrote:
>> I think the following could be a base for automatic sanitizing of sprintf
> better (preserves indentation and adds a comment)
>
> <sprintf.sed>
> s/^\([ \t]*\)sprintf \([A-Za-z_0-9]*\) \(.*\)/\1# was: sprintf \2
> \3\n\1string \2 = sprintf(\3)\n/
> </sprintf.sed>
>
> <bash>
> sed $1 -f sprintf.sed
> </bash>
>
> so for example
>
> <hansl>
> sprintf ii "%d", i-2
> </hansl>
>
> becomes
>
> <hansl>
> # was: sprintf ii "%d", i-2
> string ii = sprintf("%d", i-2)
> </nansl>
OK, very nice -- so how many packages are affected?
I agree, very nice. However, I don't think we need to get too worked
up about the command-form of sprintf. Our internal "tokenizer" can
quite happily convert it to the function form -- that's now in git.
Moreover, on closer inspection I don't think it was the sprintf
command that was responsible for the bad behavior in the script that
Peter posted recently; rather it was a bug in the "progressive" loop
code, which is now fixed.
(By the way, the --progressive option to loops dates back to before
gretl had matrices. Now that hansl is a lot more functional I'd be
happy to get rid of --progressive; everything it does can be done
quite easily using an ordinary loop plus matrices. But that would be
seriously backward-incompatible so I won't push it.)
Anyway, I've now purged the command-form of sprintf from the
documentation, replacing the command-reference page with a pointer
to the function-form. I think that's enough for now. We can issue a
deprecation without requiring that it be changed any time soon in
affected function packages: "shouldn't be used in newly written
hansl code" would be sufficient so far as I'm concerned.
The "=" versus "==" business was more pressing since the resulting
ambiguity gave rise to a pretty much insoluble parsing problem in
certain special cases. That's not an issue with sprintf command
versus sprintf function.
Allin