[Scheme-reports] Top-level cond-expand for backwards compatibility Christian Stigen Larsen 09 Jun 2013 20:40 UTC

I've used the following cond-expand trick to write R7RS programs that are
backwards compatible with RnRS implementations that support SRFI-0:

  (cond-expand
    (r7rs
      (import (scheme base)
              (scheme write)))
    (else
      (begin)))

  (display "Hello, world")
  (newline)

This works out-of-the-box on a lot of implementations:

  $ chibi-scheme cond-expand.scm  # v0.6.1
  Hello, world!

  $ csi -bq cond-expand.scm  # chicken v4.8.0.3
  Hello, world!

  $ mit-scheme --batch-mode < cond-expand.scm  # v15.3
  Hello, world!

  $ guile cond-expand.scm #  v1.8.8
  Hello, world!

  $ scheme cond-expand.scm # tinyscheme 1.39
  Hello, world!

  $ bigloo -i cond-expand.scm # v3.8c
  Hello, world!

I could not get this to work with Scheme48 or Larceny and didn't attempt it
on other implementations.

It also does not work with Mickey Scheme, because I can't figure out if I
should allow it or not.

The problem is that I believe this form of usage is strictly not valid R7RS,
at least not according to the EBNF in R7RS, ch. 7.1.6 (draft 9):

  <program> -->
    <import declaration>+
    <command or definition>+

As such, (import ...) must come before any commands and cond-expand is
defined in (scheme base) --- I'm ignoring the second definition of
cond-expand inside (import ...) blocks.

I know the document allows implementations to extend the language, given it
does not conflict with R7RS.  But there's a difference between a language
and its implementation.

So, is the code above valid in the R7RS *language*?

If not, I think we've made a small blunder with regards to backwards
compatibility.

--
Christian Stigen Larsen

_______________________________________________
Scheme-reports mailing list
Scheme-reports@scheme-reports.org
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports