schemeracketr6rs

R6RS Library body: definition after expression


Consider the following code:

#!r6rs
(library
 (test)
 (export)
 (import (rnrs))

 (define a 5)
 (begin
   (define b 4)
   (+ 3 b))
 'cont
 (define c 5)
 'done)

From the R6RS Report 7.1:

A <library body> is like a <body> (see section 11.3) except that a <library body>s need not include any expressions. It must have the following form:

<definition> ... <expression> ...

I thought it would emit error because definition of c is after expression 'cont, but this program is accepted cleanly.

After Then, I thought a and c could be exported. But, not c but b can be exported. (a can be exported as I thought.)

I think there are something I didn't realize about R6RS library rules. What is the point I'm missing? Thanks in advance.

p.s) I'm using Racket v5.3.3


Solution

  • From the R6RS 2007 specification:

    A library definition must have the following form:
    
    (library <library name>
      (export <export spec> ...)
    
      (import <import spec> ...)
    
      <library body>)
    
    
    ...
    
     The <library body> is the library body, consisting of a sequence of definitions 
     followed by a sequence of expressions. The definitions may be both for local 
     (unexported) and exported bindings, and the expressions are initialization 
     expressions to be evaluated for their effects.
    

    Thus, for your example code, an error should have been raised.