Post Reply 
multiple arguments, variable arguments, default values
04-17-2021, 01:11 PM
Post: #1
multiple arguments, variable arguments, default values
From the recent public beta announcement,

(04-14-2021 06:32 AM)Tim Wessman Wrote:  [*]Able to have multiple functions of same name with different number of arguments (no default arguments though)

I thought someone might benefit from seeing the syntax for this. And while technically correct that PPL does not support default arguments, you can still get the equivalent of default arguments as shown below.

Here's an example of multiple arguments using the same function name defined with different number of arguments.

Code:

// quadratic formula demonstration of default parameters
// QF(a, b, c)
// QF(b, c)  assumes a=1
// QF(c)  assumes a=1, b=0

EXPORT QF(a,b,c)
BEGIN
 LOCAL d;
 d:=b^2-4*a*c;
 RETURN (−b+{1,−1}*√(d))/(2*a);
END;

EXPORT QF(b,c)
BEGIN
  QF(1,b,c);
END;

EXPORT QF(c)
BEGIN
  QF(1,0,c)
END;


And here's a simple example of the variable argument syntax.

Code:

// Parallel Resistors: Adds resistors in parallel.
// Requires at least two parameters, a and b.
// The rest of the parameters are put in list c.
// If only two parameters are given, then c is {}.
// PPL allows up to 16 parameters total,
// so a and b plus 14 more in list c

EXPORT ParallelResistors(a,b,...c)
BEGIN
  c:=CONCAT(a,b,c);
  RETURN 1/ΣLIST(1/c);
END;

IMHO, these are nice additions to PPL.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
multiple arguments, variable arguments, default values - Wes Loewer - 04-17-2021 01:11 PM



User(s) browsing this thread: 1 Guest(s)