one or two arguments
11-13-2022, 03:50 PM
Post: #1
 robmio Member Posts: 170 Joined: Jan 2020
one or two arguments
Good evening everyone,
I would like to write a small program that works like this:
suppose the program is called "metto"
and I want it to work with both one argument and two arguments. For instance:
"metto(a)" -> a ^ 2
"metto(a, b)" -> a * b
How can I program the "metto" instruction to accept one argument or also two arguments?
Thanks for the help, robmio
11-13-2022, 04:15 PM
Post: #2
 Didier Lachieze Senior Member Posts: 1,641 Joined: Dec 2013
RE: one or two arguments
Since the firmware version released in Spring 2021, it’s possible to have two functions with the same name as long as they have a different number of arguments.

So in your case you can do:

Code:
EXPORT metto(a) BEGIN  a^2; END; EXPORT metto(a,b) BEGIN  a*b; END;

This works on the real calculator and windows emulator but this is not yet implemented on the IOS and Android emulators.
11-13-2022, 04:24 PM
Post: #3
 robmio Member Posts: 170 Joined: Jan 2020
RE: one or two arguments
(11-13-2022 04:15 PM)Didier Lachieze Wrote:  Since the firmware version released in Spring 2021, it’s possible to have two functions with the same name as long as they have a different number of arguments.

So in your case you can do:

Code:
EXPORT metto(a) BEGIN  a^2; END; EXPORT metto(a,b) BEGIN  a*b; END;

This works on the real calculator and windows emulator but this is not yet implemented on the IOS and Android emulators.

Thank you so much

robmio
11-13-2022, 04:44 PM
Post: #4
 ctrclckws Member Posts: 129 Joined: Sep 2018
RE: one or two arguments
The compiler or interpreter would know which one to use, based on.the number of parameters.

Really smart systems would be able to determine the type of data in the parameters and use that as well to make the decision on which flavor to call.
11-13-2022, 04:47 PM
Post: #5
 toml_12953 Senior Member Posts: 2,143 Joined: Dec 2013
RE: one or two arguments
The compiler or interpreter would know which one to use, based on.the number of parameters.

Really smart systems would be able to determine the type of data in the parameters and use that as well to make the decision on which flavor to call.

I'd use that to call the same function, such as sorting, for both numbers and strings.

Tom L
Cui bono?
11-13-2022, 04:54 PM
Post: #6
 robmio Member Posts: 170 Joined: Jan 2020
RE: one or two arguments