newRPL - Updated to build 1510 [official build remains at 1487]
|
09-07-2021, 06:07 PM
Post: #180
|
|||
|
|||
RE: newRPL - Updated to build 1497 [official build remains at 1487]
(08-24-2021 03:55 PM)Claudio L. Wrote: Unofficial ROMs updated to 1497. I'd like to submit my entry for the Suggested Command of the Month© contest... an implementation of the Check&Dispatch structure! As we all know, all RPL variants encourage a bottom-up approach to programming and this means that usually there is a main program that crunches the input data to ensure it is valid before calling the actual subroutines. The problem is that this task can become incredibly boring and convoluted, especially if the objective is to write a library. The simple task to check for three arguments on the stack being a list and two positive integers robs the programming of half the fun! To ease the burden nothing beats the elegance of SystemRPL's Ck&Dispatch structure which I propose to implement in NewRPL as follows: Code:
The check mechanism would retain SystemRPL behaviour wrt tagged objects: the arguments are checked twice; in the first pass tagged objects trigger a match only if arglist explicitly requires a tagged object; in the second pass the tags are stripped and the payload is checked to trigger a match. It's not mandatory for the arglists to have the same length: the first valid match is dispatched. The ELSE clause is optional: the default behaviour is "Bad Argument Count" in case of total mismatch or "Bad Argument Type" if at least there is a count match. Some arglist examples: Code:
Code:
The arglist concept could also be useful during library creation: at the moment the programmer must provide the number of parameters; instead it could provide a "list of arglists" albeit with the limitation that they must have the same size to comply with NewRPL programming practices. The beauty is also that as long as sub-type identification becomes smarter, CHECK..END becomes more powerful. What do you think? |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 4 Guest(s)