Ruud H.G. van Tol on Mon, 25 Dec 2023 20:09:49 +0100


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

Re: reference parameters



On 2023-12-25 19:34, Bill Allombert wrote:
On Mon, Dec 25, 2023 at 05:46:37PM +0100, Ruud H.G. van Tol wrote:
? ??listput
listput( list,x,{n}):
Not that this is a bug in the doc generator, the fixed version outputs
   listput(~list,x,{n}):

(~ is an unbreakable space in TeX).

    Sets the n-th element of the list list (which must be of type t_LIST)
equal to x. If n is omitted, or greater than the list length, appends x. The
function returns the inserted element.

    ? L = List();
    ? listput(~L, 1)
    %2 = 1
    ? listput(~L, 2)
    %3 = 2
    ? L
    %4 = List([1, 2])

Note the ~ L: this means that the function is called with a reference to L
and changes L in place.

Is that explicit reference notation still relevant?
Why not ?

We allow to omit the "~" for backward compatibility only.
This is mandatory for user-defined functions, because GP functions
are not prototyped.


OK, I presumed that (it would be safe to make) both

listput( ~L, ... ) and listput( L, ... )do exactly the same. IOW, I expect that without the "~" the function is also "called with a reference to L and changes L in place." -- Ruud