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]
where
formals ::= (formal-arguments) | rest-arg
You can of course also use the extended format in a define:
(define (nameformal-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:
The req-args are bound to actual arguments starting with the
first actual argument. It shall be an error if there are fewer actual
arguments then there are req-args.
Next the opt-args are bound to remaining actual arguemnts.
If there are fewer remaining actual arguments than there are
opt-args, then the remaining variables are bound
to the corresponding initializer, if one was specified, and
otherwise to #f. The initializer is evaluated in an
environment in which all the previous formal parameters have been bound.
If there is a rest-arg, it is bound to a list of all the
remaining actual arguments. These remaining actual arguments are also
eligible to be bound to keyword arguments. If there is no
rest-arg and there are no key-args, then it shall
be an error if there are any remaining actual arguments.
If #!key was specified, then there shall be an even number of
remaining actual arguments. These are interpreted as a series of pairs,
where the first member of each pair is a keyword specifying the argument name,
and the second is the corresponding value. It shall be an error if the first
member of a pair is not a keyword. It shall be an error if the argument name
is not the same as a variable in a key-args, unless there
is a rest-arg. If the same argument name occurs more than once
in the list of actual arguments, then the first value is used.
If there is no actual argument for a particular key-arg,
then the variable is bound
to the corresponding initializer, if one was specified, and
otherwise to #f. The initializer is evaluated in an
environment in which all the previous formal parameters have been bound.
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 the 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)))