This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
xrpl:rpl_language_overview [2019/05/05 11:35] – Two typos fixed, didn't find any others builder17 | xrpl:rpl_language_overview [2019/12/02 09:14] – Karsten75 | ||
---|---|---|---|
Line 8: | Line 8: | ||
When we talk about common aspects of all the languages, it's easiest to write xRPL where the " | When we talk about common aspects of all the languages, it's easiest to write xRPL where the " | ||
- | xRPL programming is similar to programming a HP calculator or Forth language programming. If this is not something you have done, read on for a brief introduction to xRPL and stack-based programming. <wrap info>For a more detailed CRPL explanation, | + | xRPL programming is similar to programming a HP calculator or Forth language programming. If this is not something you have done, read on for a brief introduction to xRPL and stack-based programming. <wrap info>For a more detailed CRPL explanation, |
An xRPL instruction either use arguments (data) that is on a " | An xRPL instruction either use arguments (data) that is on a " | ||
Line 26: | Line 26: | ||
</ | </ | ||
- | ===== Comments | + | ==== Comments ==== |
Adding comments makes code easier to understand, and sometimes helps the programmer or other readers to grasp complex pieces of logic. Also, after some time interval, it refreshes one's memory about exactly what a certain piece of code was intended to do. | Adding comments makes code easier to understand, and sometimes helps the programmer or other readers to grasp complex pieces of logic. Also, after some time interval, it refreshes one's memory about exactly what a certain piece of code was intended to do. | ||
Line 44: | Line 44: | ||
Likewise, note that the most recent item pushed on to the stack will also be the first item to be removed. This is referred to as LIFO (**L**ast **I**n, **F**irst **O**ut) processing. | Likewise, note that the most recent item pushed on to the stack will also be the first item to be removed. This is referred to as LIFO (**L**ast **I**n, **F**irst **O**ut) processing. | ||
- | ===== Warp Notation | + | ==== Warp Notation ==== |
An extra and optional <wrap hi> | An extra and optional <wrap hi> | ||
Line 61: | Line 61: | ||
<code prpl>3 4 add</ | <code prpl>3 4 add</ | ||
can become | can become | ||
- | < | + | < |
The open parenthesis <wrap round box> | The open parenthesis <wrap round box> | ||
Line 115: | Line 115: | ||
Both the above statements assign 7 to the variable " | Both the above statements assign 7 to the variable " | ||
+ | ==== Symbol Aliasing ==== | ||
+ | |||
+ | Many arithmetic operators | ||
+ | |||
+ | ^ Operator ^ Symbol ^ | ||
+ | | ADD | + | | ||
+ | | SUB | - | | ||
+ | | MUL | * | | ||
+ | | DIV | / | | ||
+ | | MOD | % | | ||
+ | | AND | && | | ||
+ | | OR | %%||%% | | ||
+ | | NOT | ! | | ||
+ | | POW | %%^%% | | ||
+ | | GT | > | | ||
+ | | GTE | > | ||
+ | | LT | < | | ||
+ | | LTE | <= | | ||
+ | | EQ | == | | ||
+ | | NEQ | != | | ||
+ | |||
+ | ==== Code translator ==== | ||
+ | [[https:// | ||
+ | |||
+ | For those struggling to master xRPL's post-fix format, this may be a useful tool. It can be obtained from [[https:// | ||
+ | |||
+ | Here are some sample translations, | ||
+ | |||
+ | <WRAP group> | ||
+ | <WRAP half column> | ||
+ | **mplLang code** | ||
+ | <code c> | ||
+ | x = 2 + 2 * 2; | ||
+ | </ | ||
+ | </ | ||
+ | <WRAP half column> | ||
+ | **xRPL translated code** | ||
+ | <code 4rpl> | ||
+ | 2 2 2 mul add ->x | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | <WRAP group> | ||
+ | <WRAP half column> | ||
+ | <code c> | ||
+ | z = f(x, y); | ||
+ | </ | ||
+ | </ | ||
+ | <WRAP half column> | ||
+ | <code 4rpl> | ||
+ | z = f(x, y); | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | <WRAP group> | ||
+ | <WRAP half column> | ||
+ | <code c> | ||
+ | [x, y] = CurrentCoords(); | ||
+ | </ | ||
+ | </ | ||
+ | <WRAP half column> | ||
+ | <code 4rpl> | ||
+ | CurrentCoords ->y ->x | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | <WRAP group> | ||
+ | <WRAP half column> | ||
+ | <code c> | ||
+ | if(a<b && (c+1 == -c)) [a, b, c] = 1, 2.0, 3.14; | ||
+ | </ | ||
+ | </ | ||
+ | <WRAP half column> | ||
+ | <code 4rpl> | ||
+ | <-a <-b lt <-c 1 add <-c neg eq and if | ||
+ | 1 2 3.140000 ->c ->b ->a | ||
+ | endif | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | <WRAP group> | ||
+ | <WRAP half column> | ||
+ | <code c> | ||
+ | do (1 .. 42){ | ||
+ | a = refRead(" | ||
+ | refWrite(7*(3.14+i), | ||
+ | } | ||
+ | </ | ||
+ | </ | ||
+ | <WRAP half column> | ||
+ | <code 4rpl> | ||
+ | 42 1 do | ||
+ | " | ||
+ | 7 3.140000 i add mul " | ||
+ | loop | ||
+ | </ | ||
+ | </ | ||
+ | </ |