Cω - Reference

Type-based and Wildcard Member Access

Type-based member access selects non-method members based on their type. For example given a struct that contains two x members

    struct{int x; bool x;} t = new{x=47, x=true};

we can select the integer one using the type-based selection t.int::x.

Wild-card selection selects all named and unnamed members of the given nominal type. For instance, given a stream containing Button and string values, the accessor .Button::* will select all the direct Button members regardless of their name:

  
  Button b1 = new Button(); 
  Button b2 = new Button();
  struct{Button;string;Button;string;} zs = new{ b1, "Hello", b2, "World!"};
  Button* bs = zs.Button::*; // bs = [b1, b2]

In contrast to languages such as XQuery, in Cω member access only returns members that are statically accessible:

  class ColorPoint : Point { public Color c; }
  Point p = new ColorPoint();
  object q = p;
  int* cs = p.*; // cs = [p.x, p.y], c is not accessible
  int* ds = q.*; // type error, object has no members of type int

XQuery uses the "closed world assumption", that is, the type-checker needs to know about all derived types of Point, in order to be able to type queries on non-sealed types. The closed-world assumption is unacceptable in an object-oriented setting.