Post Reply 
newRPL - build 1255 released! [updated to 1299]
04-19-2019, 01:39 PM
Post: #402
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.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: newRPL - build 1001 released! - pier4r - 12-16-2017, 08:03 AM
newRPL - on Hp 39gs - Martin Hepperle - 06-05-2019, 06:51 AM
RE: newRPL - build 1001 released! - pier4r - 12-23-2017, 10:16 AM
RE: newRPL - build 1001 released! - pier4r - 01-01-2018, 09:42 AM
t - Claudio L. - 01-01-2018, 03:06 PM
RE: newRPL - build 1001 released! - pier4r - 01-01-2018, 03:41 PM
RE: newRPL - build 1001 released! - pier4r - 01-02-2018, 04:54 PM
RE: newRPL - build 1001 released! - pier4r - 01-02-2018, 06:58 PM
newRPL - brickviking - 10-05-2018, 06:01 AM
RE: newRPL - build 1089 released! [update:build 1158] - Claudio L. - 04-19-2019 01:39 PM
How to participate? - erazor - 12-13-2019, 07:12 AM



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