Extended Formal Arguments List

The formal arguments list of a lambda expression has some extensions over standard Scheme: Kawa borrows the extended formal argument list of DSSSL, and Kawa allows you to declare the type of the parameter. More generally, you can use patterns.

lambda-expression ::= (lambda formals option-pair* opt-return-type body)
return-type ::= type
opt-return-type ::= [:: type]


formals ::= (formal-arguments) | rest-arg

You can of course also use the extended format in a define:

(define (name formal-arguments) [rtype] body)

formal-arguments ::=
    required-or-guard* [#!optional optional-arg ...] (rest-key-args | . rest-arg)

required-or-guard ::= required-arg |guard
rest-key-args ::= [#!rest rest-arg] [#!key key-arg ...]
  | [#!key key-arg ...] [#!rest rest-arg]
required-arg ::= pattern [:: type]
  | ( pattern :: type)
optional-arg ::= variable [:: type]
  | ( pattern [:: type] [initializer [supplied-var]])
supplied-var ::= variable
key-arg ::= variable [:: type]
    | ( variable [:: type] [initializer [supplied-var]] )
rest-arg ::= variable

When the procedure is applied to a list of actual arguments, the formal and actual arguments are processed from left to right as follows:

If a type is specified, the corresponding actual argument (or the initializer default value) is coerced to the specified type. In the function body, the parameter has the specified type.

If rtype (the first form of the function body) is an unbound identifier of the form <TYPE> (that is the first character is ‘<’ and the last is ‘>’), then that specifies the function’s return type. It is syntactic sugar for (as <TYPE> (begin BODY)).

You can set the properties of the resulting procedure using an option-pair. For example, to set the setter property of a procedure to my-set-car do the following:

(define my-car
  (lambda (arg) setter: my-set-car (primitive-car arg)))