It makes a list from any program and conversely. In addition, it writes an algebraic object in rpn-format and toggles between its list and program representation



Download 8.95 Kb.
Date13.05.2017
Size8.95 Kb.
#17911
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ExtUsr.RPL XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Programming in Extended User RPL (HP48G[X]) ------------------------------------------------------------------------- Autor: Wolfgang Rautenberg www.math.fu-berlin.de/user/~raut raut@math.fu-berlin.de ftp.math.fu-berlin.de/pub/usr/raut -------------------------------------------------------------------------- This is the ideal tool for all who know UsrRPL (the user programming language for the HP48) for expanding their possibilities without being forced to learn SysRPL (the System programming language which is very rich but whose learning costs a lot of time). ExtUsrRPL builds a bridge between UsrRPL and SysRPL. It contains a very small library whose commands also belong to the comprehensive operation tools package OT3. ExrUsrRPL obsoletes many devices on the ftp and www-sites, for instance BZM, a supplement to the well-known BZ-compressor which allows self-decompression. In ExrUsrRPL one can create programs containing completely arbitrary objects, e.g. compressed strings, library objects, EXTERNALs, etc. ExtUsrRPL is a good example. It starts with loading a library without visible program quotes. As a matter of fact, it has internal program quotes but these are unvisible at the user level. Complex programs of this type are created in the interactive stack rather than in the input line and may be written fairly compact. Execute ExtUsrRPL after saving your key assignment; four keys in alpha plane will be assigned, 55.4, 65.4, 75.4 and 85.4. ExtUsrRPL may be purged after setup, but leave it on the stack for a demonstration. Enter the USR-mode and press [alpha :-] (key 65.4). This key is assigned with the toggling library command ->P->. It makes a list from any program and conversely. In addition, it writes an algebraic object in RPN-format and toggles between its list and program representation. Other objects are not touched by ->P->. A program is is parsed on the stack after making a list from it with the OBJ-> command and may be reproduced with ->LIST and ->P->. In ExtUsrRPL, names and other objects may be quoted by the single quote ' (symbol Nr. 39) which prevents evaluation of the name or object following '. Thus, ' does not look at the stack as do HP commands in general, but simply puts the next object on the stack (Level 1) and continues. For instance, the UsrRPL program << 'EXUSRRPL' RCL >> may be written as ' EXUSRRPL RCL which saves 7.5 bytes. Byte saving is only a byproduct of '. Its main use is the following: Since a list cannot contain a name's delimiters, ' may be put in front of the name to prevent its evaluation. The same holds for any other list members, e.g. commands. In this way, a n y program can be created from a list, even if it is uncorrect from the point of view of UsrRPL. Here the user keys: [alpha DROP] (key 55.4). Bears the standard OBJ-> command for convenience. [alpha :-] (key 65.4). The toggling library command ->P-> described above. [alpha -] (key 75.4). Invokes the library menu, see below. [alpha -] (key 85.4), the "alpha-programming" key. It produces a ExtUsrRPL program directly from a UsrRPL-program written in the command line. Ouotings should be made with symbol 93 assigned to 85.4 in PRG mode. This symbol is the library name of the quote command. Using the single quote command ' in the command line while writing a program with 85.4 has no sense since ENTER would cause an error, hence the writing of its name. Programs written with 85.4 are compiled in such a way that the name of ' is throughout replaced by '. Moreover, all program quotes will dropped, also of programs inside lists or other programs. Since the quotes of a program inside another one disappear, the program is quoted by ' instead. Quotes of local variable environements are not dropped (this would not make sense). All this is made by the library command ->EX which executes itself after ending the alpha-programming mode with ENTER. The result is a program in ExtUsrRPL. Its structure is quite similar to a SysRPL program. But it is still readable and, in general, much shorter and faster than the original which was written in the editor. In case of need, complete information on a program's structure is gained by parsing it on the stack. The library options are |->P->| |->EX| |case| |?SKIP| |'| |'R| Only |case|, |?SKIP| and |'R| still need comment. These commands, as well as ', are user versions of a few of the many useful SysRPL commands which appear as EXTERNALs to the user. 'R is another runstream controler and looks ahead like ' and not back to the stack. |case| and |?SKIP| both take a real from the stack and then act differently depending on whether the real is 0 or not (while their SysRPL counterparts take a truth value from the stack). case simplifies the user CASE and is much faster at the same time. Let ob1,...,obn be arbitrary HP-objects and test be a test-clause, i.e., test's evaluation yield a real. Then the UsrRPL program << test CASE THEN ob1 END ob2 ... obn END >> may equivalently be written as test case ob1 ob2 ... obn. Thus, if the test result is a non-zero real (which means "True"), ob1 is evaluated and ob2,...,obn are skipped. Otherwise, i.e. if the test result is 0, then ob1 is skipped and ob2,...,obn are evaluated. Now look at the ExtUsrRPL program ... test ?SKIP ob1 ob2 ... obn ... If the test result is a non-zero real, then ob1 is skipped and execution continuous with ob2. Otherwise ob1 ob2 ... obn ... evaluate as usual. Thus, the program << test ?SKIP ob1 ob2...obn >> (with or without quotes) is equivalent to the UsrRPL program << test NOT { ob1 } IFT ob2 ... obn >>. Example. Suppose you want to write a variant of DOSUBS whose Level 3 argument could also be the empty list and whose level 1 argument need not necessarily be a program or command but as well a list, executed as if it where a program. This is useful, for the list argument can easily be produced during a program run. In UsrRPL, such a DOSUBS generalization may looks as on the left-hand side, with its translation into ExtUsrRPL on the right-hand side: << 3 PICK {} SAME 3 PICK {} SAME CASE case DROP2 THEN DROP2 DUP TYPE 8 SAME END DUP TYPE 5 SAME ?SKIP ->P-> THEN ->P END DOSUBS END DOSUBS >> The right-hand program saves more than 20% memory and is much faster. In pure SysRPL this may still shorter be written as follows (though an experienced SysRPL programmer avoids DOSUBS because of its unnamed local variables): :: 3PICK NULL{}case 2DROP DUPTYPECOL? ?SKIP x->P-> xDOSUBS ; All but the last two commands of this program appear as EXTERNALs to the user. These or any other EXTERNALs can freely be used in ExtUsrRPL-programs provided one knows their action. But even without using EXTERNALs ExtUsrRPL yields very pleasant and useful programs. The command 'R will be explained by means of an example. Let us simulate the SysRPL command ITE which is the "ahead looking" version of IFTE. The user version of ITE takes a real from the stack. If non-zero then the next object should be evaluated, otherwise the next but one. To quote the next two objects we cannot write ' ' since this simply quotes the quote. However, the program << 'R 'R IFTE >> does what we want and deserves the name ITE. For 'R quotes the first object in the program following the current one, i.e. the first object after the right-hand program delimiter. Hence, the UsrRPL program << X { 'SIN(1/X)*X' } 0 IFTE >> which defines a famous continuous function can shorter be written as << X ITE 'SIN(1/X)*X' 0 >>. After dropping the program quotes and replacing the algebraic term by its RPN version (which is readily be done with ->P-> after parsing the program on the stack) we obtain the following short version: X ITE X INV SIN X * 0. Clearly, the part X INV SIN X * is included into unvisible program delimiters. * * *

Download 8.95 Kb.

Share with your friends:




The database is protected by copyright ©ininet.org 2024
send message

    Main page