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;; This document and translations of it may be copied and furnished to
7;; others, and derivative works that comment on or otherwise explain it or
8;; assist in its implementation may be prepared, copied, published and
9;; distributed, in whole or in part, without restriction of any kind,
10;; provided that the above copyright notice and this paragraph are included
11;; on all such copies and derivative works. However, this document itself
12;; may not be modified in any way, such as by removing the copyright notice
13;; or references to the Scheme Request For Implementation process or
14;; editors, except as needed for the purpose of developing SRFIs in which
15;; case the procedures for copyrights defined in the SRFI process must be
16;; followed, or as required to translate it into languages other than
17;; English.
18
19;; [SK] the srfi-7 reference implementation using cond-expand expands
20;; a form that ends with (begin), although the empty begin isn't defined
21;; in R5RS.
22;; Gauche usually compiles (begin) into a code that does nothing.
23;; However, if there's a form like (begin <constant> (begin)), Gauche's
24;; compiler optimizer removes <constant> as well.
25;; A user might be surprised when he finds (program (code 4))
26;; returns #<undef> ---but note that 'program' form isn't an expression
27;; anyway, so expecting its result is beyond the scope of srfi-7.
28
29(define-module srfi-7
30  (export program))
31(select-module srfi-7)
32
33(define-syntax program
34  (syntax-rules (requires files code feature-cond)
35    ((program)
36     (begin))
37    ((program (requires feature-id ...)
38              more ...)
39     (begin (cond-expand ((and feature-id ...) 'okay))
40            (program more ...)))
41    ((program (files filename ...)
42              more ...)
43     (begin (load filename) ...
44            (program more ...)))
45    ((program (code stuff ...)
46              more ...)
47     (begin stuff ...
48            (program more ...)))
49    ((program (feature-cond (requirement stuff ...) ...)
50              more ...)
51     (begin (cond-expand (requirement (program stuff ...)) ...)
52            (program more ...)))))
53
54
55