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:12] – [Warp Notation] Intermediate save Karsten75 | xrpl:rpl_language_overview [2019/12/02 09:14] – Karsten75 | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== xRPL - The Language ====== | ====== xRPL - The Language ====== | ||
- | There are currently 3 scripting languages, one each for | + | |
+ | |||
+ | <wrap hi> | ||
* Creeper World III (CRPL) | * Creeper World III (CRPL) | ||
* Particle Fleet (PRPL) | * Particle Fleet (PRPL) | ||
* Creeper World 4 (4RPL) | * Creeper World 4 (4RPL) | ||
- | When we talk about common | + | When we talk about common |
- | + | ||
- | xRPL is a stack-based, | + | |
- | 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 " |
You can place arguments on the stack by typing them, or executing an instruction that will push arguments on to the stack. For instance, you can type <code prpl>2 4 5</ | You can place arguments on the stack by typing them, or executing an instruction that will push arguments on to the stack. For instance, you can type <code prpl>2 4 5</ | ||
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 106: | Line 106: | ||
endif | endif | ||
</ | </ | ||
- | Notice that spaces before or after a warp operator ( which are parentheses) don't matter. | + | Notice that spaces before or after a warp operator |
Note also that this syntax is totally optional and can be intermixed with standard RPL notation as seems appropriate. | Note also that this syntax is totally optional and can be intermixed with standard RPL notation as seems appropriate. | ||
- | < | + | < |
- | 7 -> | + | 7 ->x |
- | This means to assign 7 to the variable " | + | ->x(7) |
- | So does this: | + | </ |
- | < | + | Both the above statements |
- | Like any language, you can write some really obfuscated code if you try ([[http:// | + | ==== Symbol Aliasing ==== |
- | For instance take this clean piece of code: | + | Many arithmetic operators |
- | <code> | + | |
- | CurrentCoords GetCreeper 1 gt if | + | ^ Operator ^ Symbol ^ |
- | CurrentCoords -10 SetCreeper | + | | ADD | + | |
- | endif | + | | 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, | ||
+ | |||
+ | 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 | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
- | Here it is in bizarro form: | + | <WRAP group> |
- | < | + | <WRAP half column> |
- | endif(SetCreeper(-10(CurrentCoords(if(gt(1(GetCreeper(CurrentCoords))))))))</ | + | < |
+ | z = f(x, y); | ||
+ | </ | ||
+ | </ | ||
+ | <WRAP half column> | ||
+ | <code 4rpl> | ||
+ | z = f(x, y); | ||
+ | </code> | ||
+ | </ | ||
+ | </WRAP> | ||
+ | <WRAP group> | ||
+ | <WRAP half column> | ||
+ | <code c> | ||
+ | [x, y] = CurrentCoords(); | ||
+ | </ | ||
+ | </ | ||
+ | <WRAP half column> | ||
+ | <code 4rpl> | ||
+ | CurrentCoords ->y ->x | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
- | Here's the same code with just one oddball warp: | + | <WRAP group> |
- | < | + | <WRAP half column> |
- | endif ( if (GetCreeper(CurrentCoords) gt (1)) | + | < |
- | | + | if(a<b && |
- | ) | + | </ |
+ | </ | ||
+ | <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 | ||
</ | </ | ||
+ | </ | ||
+ | </ |