HP Forums

Full Version: Can programs have optional arguments?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Is it possible to write programs with optional arguments with default values? If so, what is the syntax?
Thx
-Donald
It is not possible, it is very related to define polymorphic functions and that is not possible in HP PPL, the alternatives can be to create 2 independent functions, or send a parameter that determines the different type of action you want to have on the data sent.
Another option, although awkward, is possible: Make the input a string, and then parse the string yourself in your program.
Thank you
Bonjour

J'ai déja fait ce genre de choses en utilisant une liste pour
transmettre/recevoir les paramètres.



Hello

I've already done this sort of thing using a list for
transmit / receive parameters.
I'm thinking like a function that has:
func(a,b,[c]), like some of the library functions....
You can create 2 functions but you can't do it like this:
EXPORT func(a,b,c=0)
...

I don't see how a list lets you do this...?
Thx
-D
Bonjour, Hello

Par exemple :
For exemple :

Code:

Export Func(p)
BEGIN
Local a,b,c
a:=p(1);b:=p(2);
IFERR c:=p(3) THEN c:=0; END;
....
....
END;

Func({10,15,2}) -> c=2
Func({10,15}) -> c=0

C'est un peu artisanal mais cela fonctionne.
It's a little crafty but it works.

Si il y a plusieurs arguments optionnels et d'autres obligatoires vous pouvez mixer.
If there are several optional arguments and mandatory others you can mix.

Code:

EXPORT Func(a,b,p)
BEGIN
LOCAL c,d,e
IF TYPE(p)==6 THEN
 c:=p(1);d:=p(2);e:=p(3)
ELSE
 c:=p;d:='def value';e:='def value';
END;
...
...
END;

Espérant vous avoir aidé.
Hoping you helped.
Hello,

PPL does not support this for user functions. sorry.
You can "emulate" it (as suggesteed before) either by creating 2 distinct functions (func2 and func3, for respectivly 2 and 3 args for example) and/or by the use of a list of input parameters.

Cyrille
Giac has support for default parameters, for example
Code:
f(x=3):=x*x; f(); f(5)
but it is probably too recent to be in the CAS of the current HP firmware.
Good!
Reference URL's