Post Reply 
[question]userRPL, functions or (sub)subprograms and directories
03-29-2017, 10:36 AM (This post was last modified: 05-21-2018 12:51 PM by pier4r.)
Post: #1
[question]userRPL, functions or (sub)subprograms and directories
A basic program in userRPL that makes use of local variables and no algebraic expression is the following (If Im not mistaken)

Code:

%%HP: T(0)A(D)F(.);
@ You may edit the T(0)A(D)F(.) parts.
@ The earlier parts of the line are used by Debug4x.

\<<
  10
  11
  \->
  uFlocal1
  uFlocal2
  \<<
    uFlocal1 SF
    uFlocal2 CF
    
    uFlocal1 FS?
    "local flag 1 set?"
    \->TAG

    uFlocal2 FS?
    "local flag 2 set?"
    \->TAG
  \>>
\>>

Now when programs gets a bit more complicated (note1) I usually try to use functions to split it in blocks.

As far as I know there are at least two ways to emulate a function:
- either I produce functions in different source files, that then I save as programs. So I have:
function1 <prog>
function2 <prog>
main <prog>
Where main makes use of function1 and function2
- or I somehow type the function in the main program and the store it to use it as recalling a variable. Like
Code:

\<<
  10
  11
  0
  \->
  uFlocal1
  uFlocal2
  funcCF
  \<<
    \<<
      @ it would work even with declaring again local variables and \-> plus a subprogram
       CF
    \>>
    'funcCF' STO
    
    uFlocal1 SF
    uFlocal2 funcCF EVAL
    
    uFlocal1 FS?
    "local flag 1 set?"
    \->TAG

    uFlocal2 FS?
    "local flag 2 set?"
    \->TAG
  \>>
\>>

Are there better ways? So far I prefer the second way (unless the program is awfully long, like 2Kb or more comments excluded) because I can use functions as defined in the main program, and not floating around the memory and maintained separatedly. Nevertheless I do not know if there may be cases that a variable cannot hold a program.

I tried to search on this site but I get interesting but not useful discussions like this.

(note 1) yes I know, ideally I should move to sysRPL or hpGCC or maybe the lua interpreter built with hpgCC, but I did not finish exploring the RPL commands in the AUR)

Wikis are great, Contribute :)
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
[question]userRPL, functions or (sub)subprograms and directories - pier4r - 03-29-2017 10:36 AM
about DIR END - pier4r - 03-29-2017, 06:15 PM



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