Post Reply 
one or two arguments
11-13-2022, 03:50 PM
Post: #1
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
Find all posts by this user
Quote this message in a reply
11-13-2022, 04:15 PM
Post: #2
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.
Find all posts by this user
Quote this message in a reply
11-13-2022, 04:24 PM
Post: #3
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
Find all posts by this user
Quote this message in a reply
11-13-2022, 04:44 PM
Post: #4
RE: one or two arguments
This feature is called overloading.
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.
Find all posts by this user
Quote this message in a reply
11-13-2022, 04:47 PM
Post: #5
RE: one or two arguments
(11-13-2022 04:44 PM)ctrclckws Wrote:  This feature is called overloading.
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?
Find all posts by this user
Quote this message in a reply
11-13-2022, 04:54 PM
Post: #6
RE: one or two arguments
(11-13-2022 04:44 PM)ctrclckws Wrote:  This feature is called overloading.
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.

this method doesn't seem to work in a #cas .... #end program
Find all posts by this user
Quote this message in a reply
Post Reply 




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