On this page:
rhombus
rhombusblock
current_  paren_  color
current_  literal_  color
current_  identifier_  color
current_  comment_  color
current_  result_  color
current_  rhombus_  colorize
current_  rhombus_  tt
8.15.0.2

9 Code as Picts🔗ℹ

 import: pict/rhombus package: rhombus-pict-lib

The pict/rhombus library provides a rhombus form form rendering literal shrubbery forms as a pict.

expression

rhombus(form)

 

expression

rhombus(form, space)

 

space

 = 

~var

 | 

~datum

 | 

~value

 | 

~result

 | 

builtin_space_keyword

 | 

symbol

 | 

symbol / space

Produces a pict that renders the text of form. Comments in form are discarded, and extra spacing is removed, but the text of shrubbery elements that have multiple representations (such as 10, 0xA, and 000010) is preserved verbatim.

Within form, #, followed by a parenthesized expression is an escape where the expression must produce a pict. The pict is rendered in place of the escape.

If space is provided as ~var, then form is italicized. If space is ~datum, then form does not get a color. If space is ~value or ~result, then a corersponding uniform color is applied. Any other space determines the initial space for rendering form sensitive to meta_label imports.

> rhombus(1+2)

image

> rhombus(arg, ~var)

image

> rhombus(3, ~result)

image

expression

rhombusblock(form, ...)

Produces a pict that renders the text of form verbatim, preserving whitespace and comments, except that #, followed by a parenthesized expression is an escape that must produce a pict to render in place of the escape.

Use rhombusblock with @ notation (see At-Notation Using @) to avoid the need to include , between multiple groups that are on separate lines.

> @rhombusblock(

   // This is an example function:

   fun add1(n):

     n + 1

  )

image

fun make_example(n, res):

  @rhombusblock(

    check: add1(#,(n))

           ~is #,(res)

  )

> make_example(@rhombus(3), @rhombus(4))

image

> make_example(@rhombus(3).scale(2), @rhombus(4).scale(2))

image

context parameter

Parameter.def current_paren_color :: Color || String:

  "brown"

 

context parameter

Parameter.def current_literal_color :: Color || String:

  "forestgreen"

 

context parameter

Parameter.def current_identifier_color :: Color || String:

  "black"

 

context parameter

Parameter.def current_comment_color :: Color || String:

  "chocolate"

 

context parameter

Parameter.def current_result_color :: Color || String:

  "darkblue"

 

context parameter

Parameter.def current_rhombus_colorize :: Any.to_boolean:

  #true

 

context parameter

Parameter.def current_rhombus_tt :: Function.of_arity(1)

Parameters that control the output of rhombus and rhombusblock.

The value of current_rhombus_tt is a function that takes a string and produces a pict for a shrubbery element. The result may be colorized, and the current font may have been adjusted to italic for ~var mode.