Make Statement

next up previous contents index
Next: Specifications Up: Statements Previous: Exit Statement

Make Statement

The make statement is used to initialize a newly created object. It may be used only within a maker (10.5.2); the maker's routine interface specifies the class of the object to be initialized. Makers use make and not return for termination: if the make statement terminates normally, this causes the maker to terminate normally.

The make statement has the form

make "{" [<ivar_inits>] "}" [then <body> end]
All make statements have a (possibly empty) ivar_inits section surrounded by curly braces. This section (which is identical to the class constructor expression (7.4)) consists of two parts:
        <ivar_inits> -> <field_inits> ";" <maker_invoc> | <field_inits> | <maker_invoc>
        <field_inits> -> <field_init> ["," <field_init>]*
        <field_init> -> <idn> ":=" <expr>
        <maker_invoc> -> <idn> [<actual_parms>] "(" [<args>] ")"

The field_inits part initializes the instance variables of the maker's class (10.4); there must be one field_init for each instance variable. (If the class has no instance variables, field_inits is not used.) The maker_invoc part is used to initialize inherited instance variables. This invocation is present iff the maker's class has a superclass (10.5.3); [tex2html_wrap2954] must name a maker (10.5.2) provided by the superclass (10.5.1).

The make statement has an optional then body end clause that can be used to do additional work after the instance variables have been assigned initial values. Within this clause, the newly created object can be referred to using the variable "self", and the instance variables of the newly-created object can be used directly as variables, as in a method body (10.4).

A make statement is evaluated in three steps; later steps are performed only if earlier steps complete normally (i.e., they do not raise an exception). The steps are:

  1. All the exprs in the field_inits are performed in an unspecified order and the resulting objects are assigned to the associated instance variables of the new object.

  2. If present, the invocation maker_invoc is performed.

  3. If present, the body is evaluated.
If all three steps complete normally, the make statement terminates and causes the containing maker to terminate normally.

A make statement cannot appear in the body of another make statement.

next up previous contents index
Next: Specifications Up: Statements Previous: Exit Statement