Next: , Previous: , Up: Syntax   [Contents][Index]

Property access using colon notation

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)).

Part lookup rules

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.

If the colon form is on the left-hand-side of an assignment (set!), then the named part is modified as appropriate.

Specific cases

Some of these are deprecated; more compact and readable forms are usually preferred.

Invoking methods

(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.

Accessing fields

class:field-name
instance:field-name
(prefix:.field-name instance)

For details see Accessing object fields.

Type literal

(type:<>)

Returns the type. Deprecated; usually you can just write:

type

Type cast

Performs a cast. Deprecated; usually you can just write:

->type

Type test

(type:instanceof? expression)

Deprecated; usually you can just write:

(type? expression)

New object construction

(type:new arg ...)

Deprecated; usually you can just write:

(type arg ...)

Getting array length

expression:length
(expression:.length)

Next: , Previous: , Up: Syntax   [Contents][Index]