one or two arguments - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: HP Prime (/forum-5.html) +--- Thread: one or two arguments (/thread-19133.html) |
one or two arguments - robmio - 11-13-2022 03:50 PM 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 RE: one or two arguments - Didier Lachieze - 11-13-2022 04:15 PM 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) This works on the real calculator and windows emulator but this is not yet implemented on the IOS and Android emulators. RE: one or two arguments - robmio - 11-13-2022 04:24 PM (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. Thank you so much robmio RE: one or two arguments - ctrclckws - 11-13-2022 04:44 PM 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. RE: one or two arguments - toml_12953 - 11-13-2022 04:47 PM (11-13-2022 04:44 PM)ctrclckws Wrote: This feature is called overloading. I'd use that to call the same function, such as sorting, for both numbers and strings. RE: one or two arguments - robmio - 11-13-2022 04:54 PM (11-13-2022 04:44 PM)ctrclckws Wrote: This feature is called overloading. this method doesn't seem to work in a #cas .... #end program |