[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Scheme-reports] Top-level cond-expand for backwards compatibility

On Mon, Jun 10, 2013 at 5:40 AM, Christian Stigen Larsen <csl@x> wrote:
I've used the following cond-expand trick to write R7RS programs that are
backwards compatible with RnRS implementations that support SRFI-0:

      (import (scheme base)
              (scheme write)))

  (display "Hello, world")

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*?

The code is not portable R7RS.  The idea is that cond-expand
and include are normal macros available in the (scheme base)
language, whereas import is a special form which should be
statically analyzable.

[I had forgotten I made a special case for cond-expand in Chibi.
This was for internal (non-portable) tests.]

Note that SRFI-0 is not available in all implementations,
so this isn't a guaranteed compatibility hack.  You might get
better portability by including the R5RS source from the
R7RS program, though the exact file lookup rules are


Scheme-reports mailing list