Managing programs with RPNEnh

  • Introduction
  • Specific program function : IF | FOR | WHILE
  • Environment functions
  • The VAR menu
  • Advanced

  • Introduction

    A program is an object that start with « and ends with », and where you can fill some functions in...
    Programs can be executed from stack or from the VAR menu.
    You can modify a program (use down arrow key if a program in on the stack)

    To create a program, you can hit the new «», the entry field will appear
    type your program, press OK to complete.

    now you have the following program « DUP 2 + » on the stack.


    Specific program functions

    Inside programs you may need to perform loops, tests..
    here are the functions that will help you :

    tests (IF)

    IF a-test THEN functions ENDIF
    execute functions only if a-test is true (not null).

    IF a-test THEN functions1 ELSE functions2ENDIF
    execute functions1 if a-test is true, and functions2 if it's false.

    test operators are : ?< lower , ?> higer, ?== equal.

    examples :
    «
    "a number please ?" input
    IF  5 ?< THEN "too low"
             ELSE "ok.."
    ENDIF
    » 
    «
    DEPTH IF 0 ?==
    THEN
      "too few argument!" 1 DISP
    ELSE
      "Please wait" 1 DISP
      md5
    ENDIF »
    
    note : the test is not mandatory, if you have a number in the stack, the THEN statement will eat it (0=false, else=true)

    Loop (FOR)

    The FOR NEXT statement allow you to perform a loop from two numbers.
    FOR expect two numbers from stack (index-start and index-end)
    NEXT close the loop.
    INDEX give back the current index into the stack . (optional)
    Exemples
    «
    1 10 FOR
     rnd
    NEXT
    10 ->list
    » 
    just give a list of 10 randomized numbers
    «
    1 10 FOR
    INDEX fact
    NEXT
    10 ->list sum
    » 
    compute : Σx=1..10( x! )


    Conditional Loop (WHILE)

    The WHILE ENDWHILE statement allow you to perform a loop with conditions.
    WHILE expect a value from stack, if it's zero, it skip while statement
    ENDWHILE close the loop, expect a value from stack, if non-zero, it jump to begining of the loop.
    Exemples


    Environment functions

    in your program, you may need to interact with user.
    If you need to display, ask, wait for user... see the list of environment interaction functions.

    The VAR menu


    In the VAR program, you can store any object type you want (numbers, matrix, strings...)

    Obviously you can also store your programs.
    Once stored, your programs can be run just by hitting the corresponding VAR key.

    Store into VAR

    To store a program (or whatever) into VAR, you must :
    1) put your program into the stack,
    2) put the name you choose into the stack (a string like "abc"),
    3) use STO function.

    Restore from VAR

    To restore the content of a program, use the RCL function.
    Put the name of the variable into stack (a string) and use RCL.



    Advanced

    Program storage

    Programs are stored into windows files.
    These files are plain ASCII text files, you can edit them outside from RPNEnh (by the notepad for example), this is very usefull for large programs.

    Program execution functions

    The run function execute a program from the stack.
    This is not the same as Exec which execute a program by it's name (stored into VAR).

    On a list

    you can perform a program on each item of a list,
    see ForEach function details, to learn more about this.

    Local Variable

    There are no local variable in RPNEnh, but you can use registers instead. see STO_A, RCL_A ( same for B and C )

    Sub programs

    you can create a kind of sub program, RPNEnh can recognize objects that start with « and ends with » as being a program...
    example :
    «
     « DUP2 * AROT + / » STO_A
     2 3 RCL_A run
     5 6 RCL_A run 
    » 
    Store your subprogram into register A (STO_A)
    The subprogram, wait for 2 number (a,b) and compute (a*b)/(a+b)

    to execute this subprogram, do RCL_A and run.

    F# Key binding

    Recently added feature : you can associate a program with a 'F' Key of your keyboard (F9,F10,F11 and F12).
    Store your program in VAR with STO then,
    You just need to rename the program file into "Key_F#" (replace # by 9,10,11 or 12).

    Optimization

    Programs are not well optimized, they are compiled "just in time"
    here is the detailled process for executing a program :
    1) convert the program into a list of functions (QLE list), see pgm->qle
    2) convert this list into as string-source , check every items (check if each function are valid), see List->Script
    3) compute the string-source with unSerialize function (low level).

    If you want to avoid the JIT compilation time (JIT:just in time = at every execution), you better to works with QLE or directly with string-sources.
    But this is the same as working in ASM instead of a high level language : it's more difficult.
    in most of time (99.9%) , « program » is enough, but if you want to learn QLE (quick list entry), just follow this link.
    As you see programs are based upon scripts.
    Note : please remind that scripts (QLE or string-source) are NOT programs.
    Both the programs and scripts can be stored into VAR and executed.
    See the summary here