03-29-2017, 10:36 AM
A basic program in userRPL that makes use of local variables and no algebraic expression is the following (If Im not mistaken)
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
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)
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)