Bill Allombert on Tue, 22 Nov 2005 11:22:01 +0100


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

Re: print1() behaviour changed


On Tue, Nov 22, 2005 at 09:44:00AM +0100, Jeroen Demeyer wrote:
> Hello list,
> 
> I noticed that the print1() function has changed.
> 
> The following shell command:
>   echo -e "print1(0);\nprint1(1);" |gp -f -q
> 
> Prints "01" (no newline) in CHANGES-1.1295
> Prints "0\n1" (with newline) in CHANGES-1.1384

Hello Jeroen, 
The behaviour in CHANGES-1.1295 was actually temporary and was not part
of any releases.

> (I didn't check in which version exactly this changed)
> 
> 
> But if there is no newline in the input:
>   echo -e "print1(0);print1(1);" |gp -f -q
> 
> Then I get "01" in both versions.

Not really! You get "01\n" with CHANGES-1.1384 and "01" with
CHANGES-1.1295!

> So it seems that whenever there is a newline in the input, a newline is 
> printed, even with print1().  I hope it's clear what I mean...

In fact, the reason is very different:

PARI/GP has the notion of 'input line': it reads a full input line
and evaluate it. If the output does not end by a \n, it adds it,
so the next output will be properly aligned.

print1(0);print1(1); is a single input line but print1(0);\nprint1(1);
is two input lines. The solution is to use braces around your
script to make it look like a single input line:
{print1(0);\nprint1(1);}

> Has this been changed on purpose?  I prefer the old way (no newline), 
> because it's very useful in scripts.  Otherwise I don't get the point of 
> the print1() function.

It does not normally affect scripts.  It only affects running scripts as
gp -q < script

In that case you can do
gp -q script </dev/null
instead, or use braces.

The difference is similar than between read() and \r:
? read(script)
? \rscript

Cheers,
Bill.