3.6 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 in values_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
values_bind as described in Propagating 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 values_bind or 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 =.
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 |
|
|
6.28 |
A binding
bind as id is essentially the same as
bind && id: it binds according the left-hand
bind as well as binding its right-hand
id as a match
to anything. The difference is that
as always treats
its right-hand
id as a pattern variable, and never as a
(prefix) binding operator, so it could be used to bind names like
_ (which would otherwise refer to the
_ binding form) and
mutable (which
would otherwise refer to the
mutable binding form).
Even when
id is not already bound, using
as
is potentially clearer than using
&& when giving a name to a
value whose components are matched in the left-hand
bind.
By itself, as binds the name as.
That is, as by itself is equivalent to
_ as as.