Post Reply 
How do I create a Subroutine using System RPL?
09-18-2022, 03:14 AM
Post: #4
RE: How do I create a Subroutine using System RPL?
(09-17-2022 07:57 PM)wmundstock Wrote:  Suppose I have the following code and I wanted to have a subroutine for when values are equal or when they are different. How do I define a subroutine?
...

What is the development tool you're using here?

"NULLNAME <objectname>" would create a reference for a hidden subroutine if the code is included in a project that is targeting a library for output. How you do that differs depending on the development environment you're using.

Also worth noting: the calling program object you've shown may work, but is inefficient in structure. While it is sometimes necessary to have nested dispatch scenarios, this isn't one of the situations where you would go that route. This situation is actually a straightforward application of the normal dispatch model, which accommodates a check for two reals as it appears you need here.

Writing the code for the Debug4x environment would look like this (using the same equality check and result you defined):
Code:
RPL

INCLUDE SandboxLibrary.h

xNAME SBLIB
::
   CK2&Dispatch
   REALREAL ::  ( note: REALREAL is in ROM and defined as #00011 )
      %= ITE
         ValuesAreEqual
         ValuesAreDifferent
   ;
;

NULLNAME ValuesAreEqual
::
   "Equal are the values"
;

NULLNAME ValuesAreDifferent
::
   "Different are the values"
;

The above code does the standard stack check for 2 arguments being present, then dispatches to the only procedure definition if both arguments are reals (or a mixture of reals/ZINTs, since the ZINTs will automatically be converted to reals by the dispatch code).

Technically speaking, there's also no need for the "::" and ";" with the two NULLNAME procedures, since there's only a single object being encapsulated. But it will work just fine with them as-is.

The above compiled and ran successfully with Debug4x.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: How do I create a Subroutine using System RPL? - DavidM - 09-18-2022 03:14 AM



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