Extended Formal Arguments List

The formal arguments list of a lambda expression has two extendsions over standard Scheme: Kawa borrows the extended formal argument list of DSSSL, and Kawa allows you to declare the type of the parameter.

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 ::=
    req-opt-args (rest-key-args | . rest-arg)

req-opt-args ::= req-arg ... [#!optional opt-arg ...]
rest-key-args ::= [#!rest rest-arg] [#!key key-arg ...]
req-arg ::=  variable [:: type] | (variable :: type )
opt-arg ::= arg-with-default
key-arg ::= arg-with-default
arg-with-default ::= variable [:: type]
    | ( variable [:: type [initializer] | initializer [:: type]] )
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)))