8.12
6.2 Definitions🔗ℹ
Binds the identifiers of
binds to the values of
rhs_expr or the
body sequence. The
body itself can include
definitions, and it normally ends with an expression to provide the
result values.
A bind can be just an identifier or id_name, or it
can be constructed with a binding operator, such as a pattern form or
:: for annotations. The number of result values must match
the number of binds. Static information is gathered from
rhs_expr or body and propagated to
lhs_bind as described in Rules for Static Information).
An identifier is bound in the expr space, and
most binding operators also create bindings in the
expr space.
When def is used with =, then rhs_expr must
not contain any immediate = terms (although = can
appear nested in blocks, parentheses, etc.). When a def group
both contains a = and ends in a block, the block is treated as
part of an rhs_expr after the =.
> def [x, y, z] = [1+2, 3+4, 5+6] |
> y |
7 |
Like
def, but for bindings that become visible only after the
let form within its definition context. The
let form
cannot be used in a top-level context outside of a module or local
block. The
let can be used with the same name multiple times
in a module or block, but the same name cannot be defined with both
def and
let within a module or block.
The
. operator works somewhat like a binding operator
that works only with identifiers, and it specifies a namespace-prefixed
identifier to bind as an extension of an already-defined namespace. More
precisely,
. to join identifiers in a binding position is
recognized literally as an operator, along the same lines as
.
used to reference a binding within a namespace or import.
See Namespaces for more information about extending
namespaces.
|
> def geometry.tau = 2 * geometry.pi |
> geometry.tau |
6.28 |