Bill Allombert on Mon, 11 Mar 2013 18:57:01 +0100


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

Re: function defaults


On Sat, Mar 09, 2013 at 05:42:01PM +0100, Joerg Arndt wrote:
> The feature of all args having default 0 is
> one of the few things in GP that I dislike.
> I guess it is there to stay for backward compatibility.
> 
> Hence I dare to ask whether some mechanism would
> be possible to disable defaults (unless given),
> for individual functions.
> 
> Made up syntax:
> 
> foo(a, b)=
> {
>    nodefaults();
>    \\ code...
> }
> 
> then calling foo without both args given
> should trigger an error.

I created a branch bill-strictargs which add a new default:

Doc: this toggle is either 1 (on) or 0 (off). If on, all arguments to new
 functions are mandatory unless the function supply an explicit default value.
 Otherwise arguments have the default value $0$.

 The default value is \kbd{0}.

Example:

? default(strictargs,1)
? f(x,e=0)=x+e
%1 = (x,e=0)->x+e
? f(5)
%2 = 5
? f()
  ***   at top-level: f()
  ***                 ^---
  ***   in function f:
  ***                 ^-
  ***   missing mandatory argument in user function.

the error message should be improved.

Note that this affect functions at compile time, but the test is done at runtime.

Please test!

Cheers,
Bill.