Block! datatype

1. Abstract

Blocks are used to represent data or code that can be evaluated at any point in time. They are a type of series! with no restriction on the type of values that can be referenced.

Blocks are delimited by opening and closing square brackets, separated by spaces.

Values and expressions in a block are not evaluated by default:

>> my-block: [print reverse "Hello" 2 * 2 42]
== [print reverse "Hello" 2 * 2 42]

>> my-block
== [print reverse "Hello" 2 * 2 42]

The native! values do and reduce are used to trigger the evaluation of expressions in a block.

  • do evaluates a block and returns the result of the last expression:

>> do my-block
olleH
== 42
  • reduce returns a copy of a block, evaluating all expressions:

>> reduce my-block
olleH
== [unset 4 42]

Block! is a member of the following typesets: any-block!, any-list!, series!

2. Creation

Block values can be created using literal syntax, or at runtime using a make constructor or a to conversion.

To create an empty block pre-allocated for 10 elements:

>> make block! 10
== []

To create a block of 10 elements with initial values set to none:

>> append/dup make block! 10 none 10
== [none none none none none none none none none none]

Using a to conversion:

>> to block! {one 2 "three" 4:00}
== [one 2 "three" 4:00:00]

>> to block! "foo 1.23 me@me.com"
== [foo 1.23 me@me.com]

>> to block! 42
== [42]

3. Literal syntax

A collection of values delimited by opening and closing square brackets, separated by spaces.

[]

[one 2 "three"]

[print 1.23]

Blocks can extend over multiple lines, and can contain other blocks.

[one
2
"three"
]

[one 2 "three" [x foo 1.23]]

Extra lines, spaces, and tabs are allowed as long as they do not break up values.

Ok: [42 print "foo"]

Not ok: [42 pr int "foo"]

4. Comparisons

All comparators can be applied on block!: =, ==, <>, >, <, >=, <=, =?. In addition, min, and max are also supported.

5. Testing values

Use block? to check if a value is of the block! datatype.

>> block? [42]
== true

Use type? to return the datatype of a given value.

>> type? [42]
== block!

results matching ""

    No results matching ""