2.5. Dot Access

A dot access is an expression that retrieves a named member of a value. It consists of a target expression E and a key K. First, E is deflated to a value v. If the value v has a member named K, that member is published. Otherwise, the expression halts.

Not all values have members. Records have members, as do many sites. A value created by an imported class has a member for each method and field of the corresponding class. A value created by a defined class has a member for each def and def class declaration in the class.

Like many expressions in Orc, a dot access is simply another form of site call. The key is converted to a special value and passed to the site call as the only argument. The site call publishes the member named by the key if it exists, and halts otherwise.

2.5.1. Syntax

[7]DotAccess::= Expression.Key  

2.5.2. Type

If the target expression E has the record type {. K0 :: T0 ,, Kn :: Tn .}, then the dot access E.Ki has type Ti.

If the target has a Java class or object type, the usual Java typing rules apply.

If the target is a site, then the type of the dot access is determined entirely by the site, like any other site call.

2.5.3. Examples

Record Access
{- Add two members of a record -} 

val displacement = {. dx = 3.0, dy = 0.3, dz = 1.1 .}

displacement.dx + displacement.dy

{-
OUTPUT:
3.3
-}
Channel Operations
{- Create a channel, and perform some operations on it. -}

val b = Channel()

  b.get() >x> b.put(x+1) >> stop
| b.get() >y> b.put(y*2) >> stop
| b.put(3) >> stop
  ;
  b.get()

{-
OUTPUT:
7
-}
{-
OUTPUT:
8
-}
Capture Channel Methods
{- Access the 'put' and 'get' members of a channel, and use them as separate sites. -}

val c = Channel()
val send = c.put
val receive = c.get

map(send, [1, 2, 3]) >>
signals(3) >>
receive() >x> 
Println("Received: " + x) >>
stop

{-
OUTPUT:PERMUTABLE:
Received: 1
Received: 2
Received: 3
-}

2.5.4. Related Links

Related Tutorial Sections