User Tools

Site Tools


xrpl:rpl_language_overview

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
xrpl:rpl_language_overview [2019/05/05 12:05] – Added <code prpl> for Regallion karsten75xrpl:rpl_language_overview [2019/08/27 06:27] – Note Symbol ALiasing relevant to 4RPL only Karsten75
Line 26: Line 26:
 </note> </note>
  
-===== 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>operator</wrap> ((In mathematics and sometimes in computer programming, an operator is a character that represents an action, as for example x is an arithmetic operator that represents multiplication. In computer programs, one of the most familiar sets of operators, the Boolean operators, is used to work with true/false values.)) change how you can choose to write the syntax.  It doesn't change anything about the stack, or how xRPL works.  It only gives you a syntax alternative that can make things easier to read in some cases. An extra and optional <wrap hi>operator</wrap> ((In mathematics and sometimes in computer programming, an operator is a character that represents an action, as for example x is an arithmetic operator that represents multiplication. In computer programs, one of the most familiar sets of operators, the Boolean operators, is used to work with true/false values.)) change how you can choose to write the syntax.  It doesn't change anything about the stack, or how xRPL works.  It only gives you a syntax alternative that can make things easier to read in some cases.
Line 115: Line 115:
 Both the above statements assign 7 to the variable "x". Choose which format you prefer and you think makes your code most readable - then be consistent. :) Both the above statements assign 7 to the variable "x". Choose which format you prefer and you think makes your code most readable - then be consistent. :)
  
 +==== Symbol Aliasing ====
 +
 +Many arithmetic operators  can be substituted with shorthand symbols **(4RPL only)**. 
 +
 +^ Operator ^ Symbol ^
 +| ADD | + | 
 +| SUB | - | 
 +| MUL | * | 
 +| DIV | / | 
 +| MOD | % | 
 +| AND | && | 
 +| OR  | %%||%% | 
 +| NOT | ! | 
 +| POW | %%^%% | 
 +| GT  | > | 
 +| GTE | >=| 
 +| LT  | < | 
 +| LTE | <= |  
 +| EQ  | == | 
 +| NEQ | != | 
 + 
 +==== Code translator ====
 +[[https://github.com/Arin112}Arin112]] wrote a code translator that can translate in-fix ((Infix notation is the notation commonly used in arithmetical and logical formulae and statements. It is characterized by the placement of operators between operands—"infixed operators"—such as the plus sign in 2 + 2.)) code to the xRPL post-fix notation. 
 +
 +For those struggling to master xRPL's post-fix format, this may be a useful tool. It can be obtained from [[https://github.com/Arin112/mplLang|github]] and is accompanied by many samples. Of course, it should be noted that the code and translation will only be up-to-date as long as the repository is maintained. 
 +
 +Here are some sample translations, taken directly from the GitHub repository:
 +
 +<WRAP group>
 +<WRAP half column>
 +**mplLang code**
 +<code c>
 +x = 2 + 2 * 2;
 +</code>
 +</WRAP>
 +<WRAP half column>
 +**xRPL translated code**
 +<code 4rpl>
 +2 2 2 mul add ->x
 +</code>
 +</WRAP>
 +</WRAP>
 +
 +<WRAP group>
 +<WRAP half column>
 +<code c>
 +z = f(x, y);
 +</code>
 +</WRAP>
 +<WRAP half column>
 +<code 4rpl>
 +z = f(x, y);
 +</code>
 +</WRAP>
 +</WRAP>
 +
 +<WRAP group>
 +<WRAP half column>
 +<code c>
 +[x, y] = CurrentCoords();
 +</code>
 +</WRAP>
 +<WRAP half column>
 +<code 4rpl>
 +CurrentCoords ->y ->x
 +</code>
 +</WRAP>
 +</WRAP>
 +
 +<WRAP group>
 +<WRAP half column>
 +<code c>
 +if(a<b && (c+1 == -c)) [a, b, c] = 1, 2.0, 3.14;
 +</code>
 +</WRAP>
 +<WRAP half column>
 +<code 4rpl>
 +<-a <-b lt <-c 1 add <-c neg eq and if
 +1 2 3.140000 ->c ->b ->a
 +endif
 +</code>
 +</WRAP>
 +</WRAP>
 +
 +<WRAP group>
 +<WRAP half column>
 +<code c>
 +do (1 .. 42){
 +a = refRead("num");
 +refWrite(7*(3.14+i), "num");
 +}
 +</code>
 +</WRAP>
 +<WRAP half column>
 +<code 4rpl>
 +42 1 do
 +"num" <-! ->a
 +7 3.140000 i add mul "num" ->!
 +loop
 +</code>
 +</WRAP>
 +</WRAP>