| 1 |
;; SRFI-7 implementation, taken from Richard Kelsey's reference implementation. |
| 2 |
;; Gauche module stuff added by Alex Shinn. |
| 3 |
|
| 4 |
;; Copyright (C) Richard Kelsey (1999). All Rights Reserved. |
| 5 |
;; |
| 6 |
;; Permission is hereby granted, free of charge, to any person obtaining |
| 7 |
;; a copy of this software and associated documentation files (the |
| 8 |
;; "Software"), to deal in the Software without restriction, including |
| 9 |
;; without limitation the rights to use, copy, modify, merge, publish, |
| 10 |
;; distribute, sublicense, and/or sell copies of the Software, and to |
| 11 |
;; permit persons to whom the Software is furnished to do so, subject to |
| 12 |
;; the following conditions: |
| 13 |
;; |
| 14 |
;; The above copyright notice and this permission notice shall be |
| 15 |
;; included in all copies or substantial portions of the Software. |
| 16 |
;; |
| 17 |
;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 18 |
;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 19 |
;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 20 |
;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
| 21 |
;; LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 22 |
;; OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 23 |
;; WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 24 |
|
| 25 |
;; [SK] the SRFI-7 reference implementation using cond-expand expands |
| 26 |
;; a form that ends with (begin), although the empty begin isn't defined |
| 27 |
;; in R5RS. |
| 28 |
;; Gauche usually compiles (begin) into a code that does nothing. |
| 29 |
;; However, if there's a form like (begin <constant> (begin)), Gauche's |
| 30 |
;; compiler optimizer removes <constant> as well. |
| 31 |
;; A user might be surprised when he finds (program (code 4)) |
| 32 |
;; returns #<undef> ---but note that 'program' form isn't an expression |
| 33 |
;; anyway, so expecting its result is beyond the scope of SRFI-7. |
| 34 |
|
| 35 |
(define-module srfi.7 |
| 36 |
(export program)) |
| 37 |
(select-module srfi.7) |
| 38 |
|
| 39 |
(define-syntax program |
| 40 |
(syntax-rules (requires files code feature-cond) |
| 41 |
((program) |
| 42 |
(begin)) |
| 43 |
((program (requires feature-id ...) |
| 44 |
more ...) |
| 45 |
(begin (cond-expand :allow-srfi-feature-id ((and feature-id ...) 'okay)) |
| 46 |
(program more ...))) |
| 47 |
((program (files filename ...) |
| 48 |
more ...) |
| 49 |
(begin (load filename) ... |
| 50 |
(program more ...))) |
| 51 |
((program (code stuff ...) |
| 52 |
more ...) |
| 53 |
(begin stuff ... |
| 54 |
(program more ...))) |
| 55 |
((program (feature-cond (requirement stuff ...) ...) |
| 56 |
more ...) |
| 57 |
(begin (cond-expand :allow-srfi-feature-id |
| 58 |
(requirement (program stuff ...)) ...) |
| 59 |
(program more ...))))) |