On this page:
examples
make_  rhombus_  eval
close_  eval
8.15.0.2

3.4 Evaluation and Examples🔗ℹ

expression

examples(option, ...,

         chunk,

         ...,

         repl,

         ...)

 

option

 = 

~label: content_expr

 | 

~eval: evaluator_expr

 | 

~indent: indentation_expr

 

chunk

 = 

~defn:

  repl

  ...

 | 

~repl:

  repl

  ...

 | 

~result:

  repl

  ...

 | 

~hidden:

  repl

  ...

 | 

~version_at_least version_string:

  chunk

  ...

 

repl

 = 

form

 | 

~error:

  form

 | 

~check:

  form

  ~is expect_form

 | 

~fake:

  typeset_form

  result_form

 | 

~blank

Evaluates forms, rendering (by default) both the form itself and the result of evaluation.

The forms to evaluate are grouped into chunks, where extra space is rendered between different chunks. When repls are provided directly to examples after any chunkss, they are implicitly grouped into a final ~repl chunk.

The keyword for a chunk determines its rendering:

Each repl within a chunk has one of several forms:

By default, a fresh evaluator is created with make_rhombus_eval to evaluate the expressions, and the evaluator is closed afterward. Supply the ~eval option to use a different evaluator.

The result of a ~label option’s expression is used to label the examples. When the result is #false, the default, then no label is shown.

The ~indent option can provide an expression to produce a nonnegative exact integer. That number of additional spaces is used to indent the example. The default is 0.

function

fun make_rhombus_eval(~lang: lang :: ModulePath = ModulePath 'rhombus',

                      ~attach: attach :: Any = #true)

 

function

fun close_eval(evaluator)

The make_rhombus_eval function creates an evaluator for a Rhombus-based language specified by lang. The evaluator does not necessary need to be closed explicitly, but closing with close_eval may improve memory use.

If attach is a true value, then a lang module instance is attached to the namespace where the enclosing document is run, and the new evaluator uses that instance in a fresh top-level namespace. Using an attached instance can be much faster than freshly loading a language in an evaluator namespace, but any state in the language ends up shared among evaluators.