Bigloo

5. Bigloo A practical Scheme compiler User manual for version 4.2c December 2015 -- DSSSL support

main page
top: | Bigloo A practical Scheme compiler User manual for version 4.2c December 2015
DSSSL support
Chapters
| Bigloo supports extensions for the Dsssl expression language [Dsssl96]: Keywords. Bigloo supports full Dsssl keywords. Named constants. Bigloo implements the three Dsssl named constants: `#!optional`, `#!rest` and `#!key`. Dsssl formal argument lists. In addition, Bigloo extends DSSSL formal parameters. It supports `#!rest` argument following `!key` arguments. In that case, the `#!rest` formal parameter is bound to the list of non-keyword values.
### 5.1 DSSSL formal argument lists
Dsssl formal argument lists are defined by the following grammar:
    <formal-argument-list> ==> <required-formal-argument>*
      [(#!optional <optional-formal-argument>*)]
      [(#!rest <rest-formal-argument>)]
      [(#!key <key-formal-argument>*) (#!rest <rest-formal-argument>?)]
    <required-formal-argument> ==> <ieee-ident>
    <optional-formal-argument> ==> <ieee-ident>
         | (<ieee-ident> <initializer>)
    <rest-formal-argument> ==> <ieee-ident>
    <key-formal-argument> ==> <ieee-ident>
         | (<ieee-ident> <initializer>)
    <initializer> ==> <expr>
When a procedure is applied to a list of actual arguments, the formal and actual arguments are processed from left to right as follows: Variables in required-formal-arguments are bound to successive actual arguments starting with the first actual argument. It shall be an error if there are fewer actual arguments than required-formal-arguments. Next, variables in optional-formal-arguments are bound to any remaining actual arguments. If there are fewer remaining actual arguments than optional-formal-arguments, then variables are bound to the result of the evaluation of initializer, if one was specified, and otherwise to `#f`. The initializer is evaluated in an environment in which all previous optional formal arguments have been bound. If there is a rest-formal-argument, then it is bound to a list of all remaining actual arguments. The remaining actual arguments are also eligible to be bound to keyword-formal-arguments. If there is no rest-formal-argument and there are no keyword-formal-arguments, the it shall be an error if there are any remaining actual arguments. If `#!key` was specified in the formal-argument-list, 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 keyword-formal-argument, unless there is a rest-formal-argument. 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 keyword-formal-argument, then the variable is bound to the result of evaluating initializer if one was specified, and otherwise `#f`. The initializer is evaluated in an environment in which all previous formal key arguments have been bound. If `#!rest` was specified in the formal-argument-list after a `#!key` formal parameter, it is bound to the list of optional non-keyword arguments. It shall be an error for an <ieee-ident> to appear more than once in a formal-argument-list. Example:
    ((lambda (x y) x) 3 4 5 6)   =>(3 4 5 6)
    ((lambda (x y #!rest z) z)
     3 4 5 6)                    => (5 6)
    ((lambda (x y #!optional z #!rest r #!key i (j 1))
        (list x y z i: i j: j))
     3 4 5 i: 6 i: 7)            => (3 4 5 i: 6 j: 1)
    ((lambda (x y #!optional z #!key i (j 1) #!rest r)
        (list x y z i: i j: j r))
     3 4 5 i: 6 i: 7 8 9)        => (3 4 5 i: 6 j: 1 (8 9))
### 5.2 Modules and DSSSL formal argument lists
Functions using Dsssl formal argument lists can be exported or imported in the same way as all regular Bigloo functions. When exporting such a Dsssl function the exact prototype of the function must be duplicated in the export clause. That is, for instance, the exportation prototype for the function:
    (define (foo x y #!optional z #!key i (j 1)) ...)
is:
    (export (foo x y #!optional z #!key i (j 1)))

This Html page has been produced by Skribe.
Last update Mon Dec 21 13:32:48 2015.