19. Bigloo -- SRFIs

Browsing
Home: | Bigloo A ``practical Scheme compiler'' for Bigloo version 2.5a April 2002
Previous chapter: | Bigloo Libraries
Next chapter: | DSSSL support
SRFIs
    19.1 SRFI 0
    19.2 SRFI 22
Chapters
    Copyright
    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. SRFIs
    20. DSSSL support
    21. Compiler description
    22. User Extensions
    23. Bigloo Development Environment
    24. Global Index
    25. Library Index
    Bibliography
| Bigloo supports various SRFIs (Scheme Request For Implementation). Some of them are integrated in the Bigloo core libraries. Some others are implemented by the means of Bigloo libraries (see Bigloo Libraries). Only the first ones are described in the manual. Check the Bigloo web page (http://www.inria.fr/mimosa/fp/Bigloo). The current Bigloo core library support the following SRFIs: `srfi-0` (Conditional execution). `srfi-6` (Basic String Ports). `srfi-8` (Binding to multiple values). `srfi-9` (Records specification). `srfi-18` (Multithreading support). `srfi-22` (Script interpreter invocation).
19.1 SRFI 0
cond-expand [clause] | bigloo syntax
The `cond-expand` form tests for the existence of features at macro-expansion time. It either expands into the body of one of its clauses or signals and error during syntactic processing. `cond-expand` expands into the body of the first clause whose feature requirement is currently satisfied (the `else` clause, if present, is selected if none of the previous clauses is selected). A feature requirement has an obvious interpretation as a logical formual, where the variables have meaning true is the feature corresponding to the feature identifier, as specified in the SRFI registry, is in effect at the location of the `cond-expand` form, and false otherwise. A feature requirement is satisfied it its formual is true under this interpretation. The formula may makes use of identifier, `and`, `or` and `not` operators. Examples:
    (write (cond-expand
              (srfi-0 (* 1 2))
              (else (+ 3 4))))
       -| 2

    (cond-expand
       (bigloo (define (command-line-arguments) (argv)))
       (else (define (command-line-arguments) '())))
The second example assumes that `bigloo` is an alias for the SRFI associated with the specification of Bigloo (i.e. the documentation for that Scheme system). When writing portable code, the case used for the feature identifier should match the one in the SRFI registry. This is to ensure that the feature identifier will be correctly recognized whether or not the Scheme system is case-sensitive. To support case-insensitive Scheme systems, the feature identifiers in the SRFI registry are guaranteed to be unique even when ignoring the case. Bigloo implements differents SRFI for the compiler and the interpreter. Thus, their are two Bigloo SRFI registers. One for the compiler and one for the interpreter. Bigloo compiler SRFI register contains at least the following symbols: `srfi-0` `srfi-6` `srfi-8` `srfi-9` `srfi-22` `bigloo` `bigloo<major-release>` `bigloo<major-release><minor-release>` With respect to the currently used Bigloo back-end, one of these symbols is registered: `bigloo-c` `bigloo-jvm` Bigloo interpreter implements the following SRFI: `srfi-0` `srfi-6` `srfi-8` `srfi-9` `srfi-22` `bigloo` `bigloo-eval` When a library is used, the name of the library is added to the compiler SRFI register. That is:
    (module foo
       (library srfi-1))

    (print (cond-expand (srfi-1 'with-srfi-1) (else 'nothing)))
       -| 'with-srfi-1
    (print (eval '(cond-expand (srfi-1 'with-srfi-1) (else 'nothing))))
       -| 'with-srfi-1
register-eval-srfi! srfi-name | bigloo procedure
This argument `srfi-name` is a symbol. It registers `srfi-name` in the Bigloo interpreter SRFI register. This function must only be used when implementing a library. The code of that library must contain one unique call to `register-eval-srfi!`. Let's suppose, for instance, a `format` library. The implementation for that library must contain an expression like:
    (register-eval-srfi! 'format)
Calling `(register-eval-srfi! name)` makes `name` supported by interpreted `cond-expand` forms. Note: There is not `register-compiler-srfi!` because the compiler manages the compiler SRFI register when the `-library` flags are used.
19.2 SRFI 22
The SRFI 22 describes basic prerequisites for running Scheme programs as Unix scripts in a uniform way. A file (henceforth a scipt) conforming SRFI 22 has the following syntax:
    <script>         ==> <script prelude>? <program>
    <script prelude> ==> #! <space> <all but linebreak>* <linebreak>
A Scheme script interpreter loads the `<script>`. It ignores the script prelude and interprets the rest of the file according to the language dialect specified by the name of the interpreter. The Scheme script interpreter may also load a different file after making a reasonable check that loading it is semantically equivalent to loading `<script>`. For example, the script interpreter may assume that a file with a related name (say, with an additional extension) is a compiled version of `<script>`. ### 19.2.1 An example of SRFI-22 script Let us consider the following Bigloo script located in a file `foo.scm':
    #! /usr/bin/env ./execute
    (module foo
       (main main))

    (define (main argv)
       (print "foo: " argv))
Let us consider the following `execute' shell script:
    $ cat > execute
    #!/bin/sh
    bigloo -i $*
Provided that `foo.scm' as the execute flag switched on, it is possible to execute it:
    $ chmod u+x foo.scm
    $ ./foo.scm
      -| foo: (./foo.scm)
The same Bigloo module can be compiled and executed such as:
    $ bigloo foo.scm
    $ ./a.out
      -| foo: (a.out)
### 19.2.2 Lazy compilation with SRFI-22 SRFI-22 can be used to implement lazy compilation. For instance, let us consider the following shell script:
    $ cat > bgl
    #!/bin/sh
    SOURCEFILE=$1
    case $SOURCEFILE in
        *.scm)
            OUTFILE=${SOURCEFILE%.scm}
            if ( bigloo -s -o $OUTFILE $SOURCEFILE ); then
                /bin/rm $OUTFILE.o
                shift
                ./$OUTFILE $@
            fi
            ;;
        *)
            echo Error: need a \*.scm file!
            ;;
    esac
And the following Bigloo script:
    #! /usr/bin/env ./bgl
    (module foo
       (main main))

    (define (main argv)
       (print "foo: " argv))
When executed in the following way:
    $ chmod u+x foo.scm
    $ ./foo.scm
      -| foo: (./foo.scm)
The Bigloo module `foo.scm` will first be compiled and then executed. Of course, one may consider more complex compiler drivers where it is first checked that the module is not already compiled.

This Scribe page has been generated by `scribeinfo`.
Last update Thu Apr 25 09:40:15 2002