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?
Can R7RS-small implementations allow only one define-library per file?
214 Views Asked by Flux AtThere are 2 best solutions below
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-libraryform.
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.
In R7RS
define-libraryis just a form, similar tolibraryin 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:
In 7.7.1 Incompatibilities with the R7RS:
Then in 7.6.1 Incompatibilities with the R6RS