A pattern declared within another pattern is represented by a Java inner class. Thus the Beta syntax:
Foo: (# Bar: (# ... #) #)
is represented as:
public class Foo { public class Bar { ... }; }
The Beta superpattern, if present, is declared as a Java superclass. Note, however, that Beta patterns without a specified superpattern do not extend java.lang.Object, but rather the Beta pattern called
Object
(which, considered as a Java class, extends java.lang.Object
like all other Java classes). This must be explicitly declared in the Java code.Static and dynamic references are implemented as instance variables. Unlike other implementations of Beta, static references are not physically incorporated into the pattern to which they belong. (At least, not as far as Java source code is concerned. Java compilers are hypothetically free to do so if they can prove that no user-visible changes result.) The only difference in the two Java declarations is that static references are declared
final
, which tells the Java compiler that their values never change. The value is automatically initialized by an appropriate expression (see below). Dynamic references do not have initializers, and are automatically set by Java to null
(the Java equivalent of "none").The exact form of the initializer of a static expression depends on the form of the ObjectDescriptor that declares it. If there is no superpattern, then the form is
new beta.Object() { ... }
where ...
is the compiled content of the (# ... #)
, a Java anonymous class. If there is a superpattern, and it is a local (non-remote) reference, then new PatternName() { ... }
results. However, if the superpattern is remote, then Java requires a more complex construction. The Beta form:Foo: (# Bar: A.B.C (# ... #) #)
appears as:
public class Foo { public A.B.C Bar = new A().new B().new C() { ... }; }
The form "new A.B.C()" will not compile.
If there is no MainPart of the ObjectDescriptor (no
(# ... #)
portion), then the class contents within the braces, as well as the braces themselves, are simply omitted.These rules for instantiation are required not only for static attributes, but also for explicit instantiation with the
"&
operator, and for implicit instantiation (a so-called "inserted object").