Address-Of Expressions

The address-of expression obtains the address of a Field or local variable as a Pointer, or the address of a Method as a Block. It is a prefix operator, and applied to the left of the expression whose address should be obtained:

var i := 5;
var a := @i; // a is now an ^Integer
a^ := 7;

Pointers on Managed Platforms

Note that the use of pointers is only allowed for Unsafe Code on the .NET platform, and is not supported at all on the Java platform. Pointers are fully supported on Cocoa and Island.

Blocks, that is method references, are supported on all platforms.

Use of @ is often unnecessary when obtaining block references, as the compiler can infer the intention based on surrounding code. But an explicit use of @ can help with type inference, or resolve ambiguities (e.g. obtaining a block reference to a method that itself returns a block.

method foo(a: Integer);

var x: block(a: Integer) := foo; // compiler knows a block reference is needed
var y := @foo;                   // implicit @ helps infer the type because else...
var z := foo;                    // ... it would just call `foo` and use its result


type BlockGenerator = block: block;  // a block that returns a block
method foo: block;                    

var x: BlockGenerator := @foo;       // x is a block reference to `foo`
var y: BlockGenerator := foo;        // y is whatever block `foo` *returned*

See Also