3

I'm trying to write something that works in both DrRacket/plt-r5rs and Gambit/gsi.

The problem I'm having is that (load "foo.scm") in Gambit does not load define-syntax-blocks. Using (include "foo.scm") in Gambit works, but of course results in a syntax error in DrRacket.

Is there any way to solve this so that I can write portable R5RS code?

Things I've tried:

  • Redefining (include "foo.scm") to (load "foo.scm") and vice versa. Problem: Illegal to redefine macros in Gambit.
  • Wrapping said redefinitions in an (if gambit ...). Problem: Illegal to put define inside if(unless inside another define).
  • Passing string with filename to an include in the library file instead. Problem: Includes in Gambit seem to happen before interpretation starts.
Erik Vesteraas
  • 4,675
  • 2
  • 24
  • 37

2 Answers2

3

In case it helps: In Racket you can use include in r5rs files:

#lang r5rs
(#%require (only racket include))
(include "foo.scm")

If you define #%require to do nothing in Gambit, then you can use the same source file in both implementations.

soegaard
  • 30,661
  • 4
  • 57
  • 106
  • Since part of the problem I'm having is that I can't redefine something for only one of them I can't see how I can use this. Am I missing something? – Erik Vesteraas Feb 26 '14 at 09:23
  • When you invoke gsi you can give it a list of files. The first can contain Gambit specific definitions. – soegaard Feb 26 '14 at 10:26
  • As far as I remember racket has the same functionality so then I could just do `(define include load)` in that file. Don't like making assumptions on how the code is run, but I guess it's the closest I'll get. – Erik Vesteraas Mar 01 '14 at 15:10
2

It's very hard to write a module that's compatible with both Gambit and Racket.

There are indeed ways you can test for a specific implementation and define things conditionally. There are, in fact, two systems for doing this: SRFI 0 and SRFI 7. Most implementations support one or the other. Not very many support both.

Gambit supports SRFI 0. Racket supports SRFI 7.

C. K. Young
  • 219,335
  • 46
  • 382
  • 435
  • To Erik: you picked this as the best answer...so what did you do? – Quasaur Mar 27 '14 at 11:52
  • I pretty much gave up on making the code I was working on portable between Gambit and Racket, as it was not really a requirement for that particular project, but just something that would be nice. Especially when I figured out how to get what I wanted from Gambit in Racket(the answer to the question "is this currently running in a terminal?"). – Erik Vesteraas Apr 04 '14 at 07:43