Next: , Up: Optional Arguments


5.8.3.1 let-optional Reference

The syntax let-optional and let-optional* are for destructuring rest argument lists and giving names to the various list elements. let-optional binds all variables simultaneously, while let-optional* binds them sequentially, consistent with let and let* (see Local Bindings).

— library syntax: let-optional rest-arg (binding ...) expr ...
— library syntax: let-optional* rest-arg (binding ...) expr ...

These two macros give you an optional argument interface that is very Schemey and introduces no fancy syntax. They are compatible with the scsh macros of the same name, but are slightly extended. Each of binding may be of one of the forms var or (var default-value). rest-arg should be the rest-argument of the procedures these are used from. The items in rest-arg are sequentially bound to the variable names are given. When rest-arg runs out, the remaining vars are bound either to the default values or #f if no default value was specified. rest-arg remains bound to whatever may have been left of rest-arg.

After binding the variables, the expressions expr ... are evaluated in order.