Bill Allombert on Sun, 20 Jul 2025 15:57:42 +0200


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

Re: question on encapsulating format for a gp pari function


On Mon, Jun 30, 2025 at 09:14:03AM -0700, American Citizen wrote:
> Hello:
> I write my gp pari functions as like this
> 
> {fun(a)=
> my(b);
> b=a;
> return(b);
> }
> 
> But recently I noticed that someone who I highly respect writes in this way.
> fun(a)=
> {
>   my(b);
>   b=a;
>   return(b);
> }
> 
> What is the preferred way of doing this? Is the second to allow the function
> signatures to be visible?

As far as GP is concerned this is equivalent, since GP ignore spaces.
The second form is more modern-looking.
In general we omit return(), which is not necessary.

We provide a tutorial covering this topic:
https://pari.math.u-bordeaux.fr/Events/PARI2019b/talks/prog.pdf


Very old GP scripts (for PARI 1.39.15) were written this way

{fun(a,
     b)=
  b=a;
  b;
}
because local() did not exist yet.

Cheers,
Bill.