newRPL - build 1255 released! [updated to 1299]
04-19-2019, 01:39 PM
Post: #402
 Claudio L. Senior Member Posts: 1,840 Joined: Dec 2013
RE: newRPL - build 1089 released! [update:build 1158]
(04-19-2019 01:11 PM)compsystems Wrote:  Hello
I do not know if the following was already discussed: Optional Arguments
No, it wasn't because it does not apply in RPN/RPL.

(04-19-2019 01:11 PM)compsystems Wrote:  The RPN commands of the hp48 / 50 interpret a number of fixed arguments, while in the functional standard notation some languages the number of call arguments can be variable
Wrong: all commands in RPN/RPL are free to use how many elements (arguments) they want from the stack.

(04-19-2019 01:11 PM)compsystems Wrote:  I think the only way in RPN is to specify the number of arguments
Wrong again, on all languages, each command/function knows how many arguments it needs depending on the values of other arguments or any other markers.
In other languages you ARE providing the number of arguments when you enclose them in parenthesis. Of course you can do the same in RPL, just put a marker on the stack where the arguments start, everything below that is an argument.
Code:
 "LASTARGUMENT" 1 2 3 COUNTARGS
The command COUNTARGS would simply look for the string "LASTARGUMENT" in the stack and use it as an end marker, everything below is an argument. Of course, providing explicitly the number of arguments is easy and quick, but not the only way as you stated (and this is true for all languages, not just RPL).
By the way, some RPL commands require different number of arguments depending on the type of arguments passed, some others even analyze the arguments to make a smart "guess" at how many arguments are needed (look at DOLIST in the AUR, on stock 50g it requires or not an explicit number of lists depending on analyzing the program you provided to see how many arguments it needs).
This is also the same for other languages, printf() analyzes the string you passed on the first argument to see how many arguments it needs and their type.

To close this: there's no need for anything special to do variable arguments in RPL.
 « Next Oldest | Next Newest »