| Bill Allombert on Thu, 07 Sep 2023 20:11:39 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| Re: Questions on PARI/GP formatting |
On Tue, Sep 05, 2023 at 09:24:02PM +0200, hermann@stamm-wilbrandt.de wrote:
> On 2023-09-05 18:22, Bill Allombert wrote:
> > We offer this tutorial:
> >
> > <https://pari.math.u-bordeaux.fr/Events/PARI2019b/talks/prog.pdf>
> >
> Thanks, looks good.
>
> > > I added whitespace where it helped me, but overall it is not
> > > consistent.
> > > Are there best practices wrt GP optional whitespace use?
> > >
> Examples seem to indicate mostly not to use optional whitespace.
GP ignores whitespaces anyway, so feel free to pick the whitespace
policy you prefer.
> > > I use "break", should it be "break()" instead?
> >
> > Yes, because break has an optional argument.
> >
> I added "()" to my script breaks -- tutorial example on page 8 misses "()"
> as well.
I did that due to vertical space constraint (I would have needed to add a
newline to avoid the difficult to read 'break()));' ).
> I changed my gist, should now look mostly like the examples in tutorial:
> https://gist.github.com/Hermann-SW/50514eaf06b4d91ec6bcee5e49732dff
>
>
> Few followup questions:
>
> 1)
> I cannot put "my()" in first line of function, because in some cases need to
> break() before.
> Is that OK?
Sure.
> 2)
> Multi assignment seems to work in "my()", is that OK?
> ...
> test(v)=
> {
> if(#v<4,
> break());
> my([l,n,p,q]=v,pnr,qnr,sqrtm1);
> ...
Sure.
> 3)
> Variable "n" is not used, but needed for multi assignment to work.
> Are there anonymous variables to indicate that?
No, but you can omit n:
my([l,,p,q]=v,pnr,qnr,sqrtm1);
> 4)
> "for*" loops work multiline only inside "{...}".
> I had to put braces around last loop calling "test()" to get multiline
> foreach working.
> Is that OK?
>
> ...
> };
>
> {
> foreach(rsa,v,
> test(v));
> }
Sure!
Cheers,
Bill