Post Reply 
newRPL - Updated to build 1510 [official build remains at 1487]
09-08-2021, 05:21 PM
Post: #183
RE: newRPL - Updated to build 1497 [official build remains at 1487]
I believe that a custom case structure is an overengineered solution, the simple command CKARG appears more reasonable (a building block that can be used in a normal case structure, or in a wholly different manner if you want).

If I may, I'd like to request replacing the simple true/false flag with an index of which type in the list matched (with 0 as placeholder for no match, like POS does). In RPL anything that isn't 0 counts as true anyway, so the value can be used for the same purposes, and performance-wise it should be a freebie, but in situations where the cases are similar but not quite the same the programmer could use this index to pull the type-specific handling code out of a list, then follow up with the common code. For instance, if your program shall accept a list or a vector and treat either as coordinates, that would allow something like this, based around AXL to coerce the input into one canonical format:
Code:
... CKARGTF
IF DUP NOT
THEN DROP "Bad Argument Type" DOERR
ELSE { AXL \<< \>> } SWAP GET EVAL
  ...
END
(NOP would be nice to have by the way, here I used an empty program instead. And yes, I'm using traditional RPL trigraphs instead of newRPL's Unicode glyphs; should be understandable either way.)
This kind of dispatching also opens the door to a third command that returns the index but retains the error-out on no match.

In the end, CKARGTF would arrive at something like this UserRPL implementation:
Code:
\<<
  SWAP
  1. + (adjusting stack level parameter for the types list in the way)
  PICK (fetch the object for examination; also serves as a stack depth guard)
  TYPE POS
\>>
This one doesn't have auto-detagging and such, but it should serve as a prototype to experiment with before deciding on whether to implement it as a native command. Additional features can be prototyped as wrappers around this, e.g. the error-checking CKARG would be
Code:
\<<
  IF CKARGTF NOT
  THEN "Bad Argument Type" DOERR
  END
\>>
As a hint for a tag-stripping wrapper, DTAG would be the key command; though I didn't check if newRPL has that one yet.


Side note: I'm a SysRPL programmer, but in >90% of my programs type-checking doesn't use CK&Dispatch1 or its siblings. It's not as awesome as it appears to be. Checking each stack level (or group of them, in some cases) in turns is where it's at.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: newRPL - Updated to build 1497 [official build remains at 1487] - 3298 - 09-08-2021 05:21 PM
Navigating through sub-menus - Gilles - 05-13-2023, 11:31 AM
It's a mystery to me... - Klaus - 11-27-2023, 12:24 PM



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