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


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

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

7.7.2 Specific cases

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

7.7.2.1 Invoking methods

(instance:method-name arg ...)
(class:method-name instance arg ...)
(class:method-name arg ...)
(*:method-name instance arg ...)

For details see Method operations.

7.7.2.2 Accessing fields

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

For details see Field operations.

7.7.2.3 Type literal

(type:<>)

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

type

7.7.2.4 Type cast

(type:@ expression)

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

->type

7.7.2.5 Type test

(type:instanceof? expression)

Deprecated; usually you can just write:

(type? expression)

7.7.2.6 New object construction

(type:new arg ...)

Deprecated; usually you can just write:

(type arg ...)

7.7.2.7 Getting array length

expression:length
(expression:.length)

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