2 Dynamically-Typed Core
The syntax for method declarations (again, excluding aspects relating to static typing and encapsulation) is as follows:objectshape;methoddraw(s, d) { (-- drawss on display d--) }methodmove_to(s, new_center) { (-- moves to new_center--) }objectcircleisashape;methodarea(c@circle) { c.radius * c.radius * pi}methodcircum(c@circle) { c.radius * 2 * pi }objectrectangleisashape;methodarea(r@rectangle) { r.length * r.width }methodcircum(r@rectangle) { 2 * r.length + 2 * r.width }methoddraw(r@rectangle, d@Xwindow) { (-- overridedraw for the case of drawing rectangles on X windows--) }objectrhombusisashape;objectsquareisarectangle, rhombus; -- inheritsarea method, but overrides circum methodcircum(s@square) { 4 * s.length }
method_decl ::= "method" method_name "(" [formals] ")" [pragma]
"{" (body | prim_body) "}" [";"]
method_name ::= msg_name | op_name
msg_name ::= name
formals ::= formal { "," formal }
formal ::= [name] specializer formal names are optional, if never referenced
specializer ::= "@" named_object specialized formal
| empty unspecialized formal
(op_name is the token for infix and prefix operators beginning with a punctuation symbol; see appendix A.2 for more details.)As a convention, we indent method declarations under the associated object declaration. This has no semantic implication, but it helps to visually organize a collection of object and method declarations in the absence of a more powerful graphical programming environment [Chambers 92b].
Generated with Harlequin WebMaker