Next: Programs and Bodies, Previous: Primitive expression syntax, Up: Syntax [Contents][Index]
The colon notation accesses named parts (properties) of a value.
It is used to get and set fields, call methods, construct compound symbols,
and more.
Evaluating the form owner:property
evaluates the owner
then it extracts the named property
of the result.
property-access-abbreviation ::= property-owner-expression:
property-name property-owner-expression ::= expression property-name ::= identifier |,
expression
The property-name is usually a literal name,
but it can be an unquoted expression (i.e. following a ,
),
in which case the name is evaluated at run-time.
No separators are allowed on either side of the colon.
The input syntax owner:part
is translated by
the Scheme reader to the internal representation ($lookup$ owner (quasiquote part))
.
Evaluation proceeds as follows.
First property-owner-expression is
evaluated to yield an owner object.
Evaluating the property-name yields a part name,
which is a simple symbol: Either
the literal identifier, or the result of evaluating the
property-name expression.
If the expression evaluates to a string, it is converted to
a symbol, as if using string->symbol
.
gnu.mapping.HasNamedParts
,
then the result is that of invoking the get
method of the owner
with the part name as a parameter.
As a special case of this rule, if owner is a
gnu.mapping.Namespace
, then the result is the
compound symbol in that namespace.
java.lang.Class
or a gnu.bytecode.ObjectType
,
the result is the static member named part
(i.e. a static field, method, or member class).
java.lang.Package
object, we get the member
class or sub-package named part.
Note you can’t use colon notation to invoke instance methods
of a Class
, because it will match a previous rule.
For example if you want to invoke the getDeclaredMethod
method of the java.util.List
, you can’t write (java.util.List:getDeclaredMethod
because that will look for a static method in java.util.List
.
Instead, use the invoke
or invoke-sttic
method. For example:
(invoke java.util.List 'getDeclaredMethod)
.
If the colon form is on the left-hand-side of an assignment (set!
),
then the named part is modified as appropriate.
Some of these are deprecated; more compact and readable forms are usually preferred.
(
instance:
method-name arg ...)
(
class:
method-name instance arg ...)
(
class:
method-name arg ...)
(*:
method-name instance arg ...)
For details see Calling Java methods from Scheme.
class:
field-name instance:
field-name(
prefix:.
field-name instance)
For details see Accessing object fields.
expression:length
(
expression:.length)
Next: Programs and Bodies, Previous: Primitive expression syntax, Up: Syntax [Contents][Index]