Can R7RS-small implementations allow only one define-library per file?

210 Views Asked by At

Are compliant R7RS-small implementations allowed to impose a restriction on the number of define-library per file? Some R7RS-small implementations such as Guile 3.0.7 only allow one define-library per file. Is this a deviation from the standard, or is it allowed by R7RS-small?

2

There are 2 best solutions below

0
On

In R7RS define-library is just a form, similar to library in R6RS. I don't see any allowances in either case that conforming implementations may constrain a file to contain only one such form.

But the Guile documentation has something to say on the matter. In 7.7 R7RS Support:

Happily, the syntax for R7RS modules was chosen to be compatible with R6RS, and so Guile’s documentation there applies.

In 7.7.1 Incompatibilities with the R7RS:

As the R7RS is a much less ambitious standard than the R6RS (see Guile and Scheme), it is very easy for Guile to support. As such, Guile is a fully conforming implementation of R7RS, with the exception of the occasional bug and a couple of unimplemented features....

Then in 7.6.1 Incompatibilities with the R6RS

Multiple library forms in one file are not yet supported. This is because the expansion of library sets the current module, but does not restore it. This is a bug.

0
On

Yes, I think they can (and, perhaps, should).

If you look at the formal syntax & semantics in r7rs.pdf then

  • A program is one or more import declarations followed by one or more commands or definitions. Commands and definitions don't include define-library.
  • A library is exactly one define-library form.

So from that you can conclude that a program doesn't include define-library forms, and a library includes exactly one such form.

Now that document doesn't say how all this maps into files at all, so it's up to the implementation to define that. I think it would be perfectly possible for an implementation to say that the mapping of files to library files should be 1-1, so any given library file contains exactly one library. It would also be possible to have files which contained mixtures of a program and one or more libraries, of course.

In the case where libraries are in their own files (which is obviously the more interesting case in terms of allowing reuse) something has to turn a library name into a file. And that would make it reasonably natural to put exactly one library in each file.


If it was me, I'd allow files which contain a mixture of a program and one or more libraries directly present, but for files which were just libraries I'd allow just one in each file.