Struct



next up previous contents index
Next: Oneof Up: No Title Previous: Record

Struct

"Struct"s are immutable records. Like the "record" types, there is a method to read each field of a "struct". [tex2html_wrap2977]Structs are created using constructors; the form of these constructors is identical to those for type "record".

A "struct" type "st" has the following methods. ([tex2html_wrap2978]rt is the related "record" type, i.e., it has the same field names and types in the same order.)

Methods for "struct" type "st"

  a ( ) returns (T)
      % (here a is a field name and T is the corresponding type)
      % effects   returns the object stored in the a component of self.

  replace_a (x: T) returns (st)
      % effects   returns a new struct containing the objects in the
      %           corresponding fields of self except that x is in field a

  to_r ( ) returns (rt)
      % effects   returns a new record whose fields contain the objects in the
      %           corresponding fields of self

  equal (x: st) returns (bool)
        where all field types T of st have equal (T) returns (bool)
      % effects   returns true if x and self are pairwise equal (using the equal
      %           methods for the fields) else returns false

  similar (x: st) returns (bool)
        where all field types T of st have similar (T) returns (bool)
      % effects   returns true if x and self are pairwise similar (using the similar
      %           methods for the fields) else returns false

  copy ( ) returns (st)
        where all field types T of st have copy ( ) returns (T)
      % effects   returns a new struct containing as components copies of the objects
      %           (using the object's copy method) in the corresponding fields of self.

  unparse ( ) returns (string)
        where all field types T of st have unparse ( ) returns (string)
      % effects   returns a string representing the value of self.  The form of the
      %           string is struct{\tex{$n_1$}: \tex{$f_1$},..., \tex{$n_n$}: \tex{$f_n$}}, where \tex{$n_i$} is the name of the
      %           ith struct field and \tex{$f_i$} is the unparsing of that field.



theta-questions@lcs.mit.edu