ROPE Language - Anchor Brackets

ROPE's actions words (like "add", "println") etc take (pop) items off the top of the stack, manipulate them and possibly put (push) items back as a result. Most action words have a default number of items that they pop off the stack. On the whole those defaults are obvious and instinctive.

For example: the "add" action by default adds the top 2 items and pushes back their sum. So..

 1 3 5 11 add

leaves the values 1,3,16 on the stack because "add" has taken the 5 and 11, added them and pushed back the resulting value.

If you want to change the number of arguments that "add" processes, you use brackets like this..

 1 add( 3 5 11 )

This leaves the values 1 and 19 on the stack because "add" has taken the three values in brackets, added them and pushed back the result. This syntax is called "AnchorBrackets" because what rope does when it sees this style of syntax is this..

  1. pushes the number 1 onto the stack
  2. pushes an "anchor" onto the stack, marked with a reference to the "add" action. But it does not execute the "add" at this point.
  3. pushes the numbers 3, 5 and 11 onto the stack. At this point, the stack holds 5 things - the number 1, the "add" anchor and the numbers 3, 5 and 11 (in that order).
  4. When it encounters the ")" mark, ROPE scans backwards down the stack for the anchor nearest the top and removes it from the stack. Then it pops all the values that were pushed after the anchor was dropped and processes them (adds them together).
  5. Finally, the "add" action pushes back the result.

It should be noted that some ROPE action words must not be called with AnchorBrackets in this way - but it is the run-time (rather than the compiler) that complains if the wrong syntax is used. Similarly, some action words must be called with AnchorBrackets because they have no default number of items to take from the stack.