Post Reply 
Can programs have optional arguments?
09-09-2017, 01:56 AM
Post: #1
Can programs have optional arguments?
Is it possible to write programs with optional arguments with default values? If so, what is the syntax?
Thx
-Donald
Find all posts by this user
Quote this message in a reply
09-09-2017, 02:52 AM
Post: #2
RE: Can programs have optional arguments?
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.

Viga C | TD | FB
Visit this user's website Find all posts by this user
Quote this message in a reply
09-09-2017, 04:09 AM
Post: #3
RE: Can programs have optional arguments?
Another option, although awkward, is possible: Make the input a string, and then parse the string yourself in your program.

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
09-09-2017, 05:13 AM
Post: #4
RE: Can programs have optional arguments?
Thank you
Find all posts by this user
Quote this message in a reply
09-09-2017, 03:34 PM
Post: #5
RE: Can programs have optional arguments?
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.

Sorry for my english
Find all posts by this user
Quote this message in a reply
09-09-2017, 10:07 PM
Post: #6
RE: Can programs have optional arguments?
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
Find all posts by this user
Quote this message in a reply
09-10-2017, 05:35 AM
Post: #7
RE: Can programs have optional arguments?
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.

Sorry for my english
Find all posts by this user
Quote this message in a reply
09-11-2017, 05:13 AM
Post: #8
RE: Can programs have optional arguments?
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

Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP.
Find all posts by this user
Quote this message in a reply
09-11-2017, 04:52 PM
Post: #9
RE: Can programs have optional arguments?
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.
Find all posts by this user
Quote this message in a reply
09-11-2017, 08:24 PM
Post: #10
RE: Can programs have optional arguments?
Good!
Find all posts by this user
Quote this message in a reply
Post Reply 




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