9.0

10.3 Interactive Rhombus REPL🔗ℹ

As noted in Running Rhombus Programs, a Rhombus read-eval-print loop (REPL) for evaluating individual Rhombus expressions and definitions can be started with

rhombus

or

racket -I rhombus

DrRacket also provides a REPL in its bottom pane after running a Rhombus program, including the empty program #lang rhombus.

One catch with Rhombus’s Shrubbery Notation is that interactive evaluation does not always know where to stop, because it reads definitions and expression line-by-line. For example, with the single-line input 1 + 2, then a programmer almost certainly means to add two numbers.

> 1 + 2

3

But it’s also possible that a programmer means to add more numbers by continuing with an indented + on the next line.

> 1 + 2

    + 3

6

The Rhombus REPL supports only the former interaction. Naturally, the REPL waits for multi-line input with an opening parenthesis, bracket, bracket or quote is not yet closed.

> (1 + 2

     + 3)

6

The REPL also looks for multiple lines when the first line contains a : (not within parentheses, brackets, braces, or quotes). When a : is found, the REPL continues reading until it sees a line containing only whitespace. The : rule makes the following function definition work interactively, where an extra blank line must be entered to terminate the definition:

> fun f(x):

    x + 2

    

> f(1)

3

To support multi-line input where the first line does not contain :, the Rhombus REPL recognizes an input that is an immediate block, and it evaluates the sequence inside the block instead of the block as a whole. So, enter multiline mode in the Rhombus REPL by starting with :, potentially on its own line.

> : 1 + 2

      + 3

      

6

> match [1, 2, 3]

match: expected more terms

> :

    match [1, 2, 3]

    | [a, b, c]: a + b + c

      

6

> if 1 > 2

if: expected more terms

> :

    if 1 > 2

    | "oops"

    | "right"

  

"right"

> if 1 > 2 | "oops" | "right"

"right"