Programming Language for Old Timers


by David A. Moon
February 2006 .. September 2008

Comments and criticisms to dave underscore moon atsign alum dot mit dot edu.


Previous page   Table of Contents   Next page


Parameter Lists

A method requirement specification, a method definition, a class constructor specification, and a function constructor all use a parameter list to describe the arguments received by a function and the values returned. A parameter list consists of up to four sections: required parameters, optional parameters, keyword parameters or rest parameter, and results. All sections are optional. Optional, keyword, and rest parameters work much the same way as in Common Lisp.

In a function constructor, an optional fifth section precedes the normal four sections. This is the name section, consisting of the keyword name: followed by a name which identifies the constructed function and method for debugging purposes. This is not considered part of the parameter list even if it looks that way.

Each section except the required parameters is introduced by a keyword: optional:, key: or rest:, and result: respectively. Within each section there are one or more parameter specifiers. Each parameter specifier except the last one in the entire parameter list is followed by a comma.

A parameter specifier contains a parameter name with an optional type specifier. This uses the syntactic type typed-variable described in the next section. For optional and keyword parameters, an optional default value specifier follows. A default value specifier consists of the absolute particle "=" followed by a default value expression. If the argument is not present, the default value expression is evaluated in a scope in which the preceding parameters are visible. If no default value is present, it defaults to false.

The type restriction in a parameter specifier requires that the value of an argument that becomes the value of this parameter must be of the specified type. A type restriction on a rest parameter applies to each individual argument that becomes an element of the rest parameter.

If no results section is present in a parameter list, the function can return any number of values of any type. When a results section is present, the function returns exactly the specified number of values and the values are restricted to the specified types. The names of results are only for documentation and do not become visible as definitions in the program.

The definition of a parameter is never assignable.

The syntax of parameter-lists could almost be defined like this, except this definition is not LL(1) because using commas this way requires two-token lookahead:

defsyntax parameter-list
      [ { ?required is typed-variable & ~^ , }* & ~^ , ]
      [ optional: { ?optional is typed-variable [ ~^ = ?optional-default ] & ~^ , }+ & ~^ , ]
      [ { rest: ?rest is typed-variable |
          key: { ?key is typed-variable [ ~^ = ?key-default ] & ~^ , }+
        } & ~^ , ]
      [ result: { ?result is typed-variable & ~^ , }+ ]
      => ...

The syntactic type parameter-list is defined in the compiler module. It has multi-valued slots for each parameter type.

---TBD more detail on the class parameter-list


Previous page   Table of Contents   Next page