21. Bigloo -- DSSSL support

Browsing
Home: | Bigloo A ``practical Scheme compiler'' User manual for version 2.6b December 2003
Previous chapter: | SRFIs
Next chapter: | Compiler description
DSSSL support
21.1 | DSSSL formal argument lists
21.2 | Modules and DSSSL formal argument lists
Chapters
| Acknowledgements
1. | Table of contents
2. | Overview of Bigloo
3. | Modules
4. | Core Language
5. | Standard Library
6. | Pattern Matching
7. | Object System
8. | Threads
9. | Regular parsing
10. | Lalr(1) parsing
11. | Errors and Assertions
12. | Eval and code interpretation
13. | Macro expansion
14. | Command Line Parsing
15. | Explicit typing
16. | The C interface
17. | The Java interface
18. | Bigloo Libraries
19. | Extending the Runtime System
20. | SRFIs
21. | DSSSL support
22. | Compiler description
23. | User Extensions
24. | Bigloo Development Environment
25. | Global Index
26. | Library Index
| Bibliography
| 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.
21.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>*)]
    <required-formal-argument> ==> <ident>
    <optional-formal-argument> ==> <ident>
         | (<ident> <initializer>)
    <rest-formal-argument> ==> <ident>
    <key-formal-argument> ==> <ident>
         | (<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 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 arguments have been bound.

It shall be an error for an <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)

21.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 named constants must be included in the prototype of the function but the formal parameters are not required. That is, for instance, the exportation prototype for the function:

    (define (foo x y #!optional z #!key i (j 1)) ...)

looks like:

    (export (foo x y #!optional #!key))

This Scribe page has been generated by `scribeinfo`.
Last update Tue Dec 16 13:46:41 2003