Nested block structures
Block forms can be defined and/or called within the context of other block structures, providing a powerful and expressive mechanism for controlling query execution and behavior.
The block layer of the 1010data Macro Language provides the mechanism by which queries can be modularized and parameterized. It is often very useful to define and/or call one block during the execution of another. In other words, blocks can behave like nested functions and closures.
There are numerous block forms that can be used to specify the way query execution behaves. This topic will cover each, but the first distinction that needs to be drawn is that between named and unnamed block forms.
Unnamed block forms execute within a query wherever they are defined. They cannot be named and cannot accept parameters.
<isolate>
- A non-closure nested form.<isolate>
cannot capture values from its enclosing context.<blocklet>
- A partial closure.<blocklet>
can capture values from its enclosing context, but modifications to values it captured do not persist after its execution is complete.<let>
- A full closure.<expand>
can capture values from its enclosing context, and modifications to values it captured persist after execution is complete.
Named block forms are defined in one place, such as a <library>
, and can
be called within the context of another block form.
<call>
,
<insert>
, or<expand>
:<block>
- If defined as part of a library, it must be named and will only execute when explicitly called by name using one of the invocation methods listed below.<defblock>
- Must be named and will only execute when explicitly called by name using one of the invocation methods listed below.
<call>
- When invoked using<call>
, a named block cannot capture values from its enclosing context. Causes the named block to behave like an<isolate>
structure.<insert>
- When invoked using<insert>
, a named block can capture values from its enclosing context, but modifications to values it captured do not persist after execution. Causes a named block to behave like a<blocklet>
structure.<expand>
- When invoked using<expand>
, a named block can capture values from its enclosing context, and modifications to values it captured persist after execution. Causes a named block to behave like a<let>
form.