Racket can not only run Racket programs (i.e.
.rkt files), it can also run Scheme programs without requiring any modifications to the source code. Regular Racket files require the
#lang declaration at the beginning of the source file, which is not valid in Scheme. Thankfully, Racket can run Scheme files without requiring the
#lang declaration. Here's how to run r5rs and r6rs Scheme programs using Racket.
Racket installations come with the
r6rs languages by default. An
r5rs file may look like this:
#lang r5rs (display "Hello")
But the problem is that we do not want to write the
#lang line, because that turns the program into a Racket program. To avoid the need to declare the language using
#lang, you can run the programs using the
--script command line options. For example,
racket -I r5rs --script program.scm (or
racket -I r5rs -r program.scm for short). The
-I option sets the language so that no
#lang line is required in the source file. The
--script option runs the program.
Typing out the racket command to select the language is tedious, so Racket comes with the
plt-r6rs executables, which run r5rs Scheme and r6rs Scheme programs respectively. To run an r5rs Scheme program:
plt-r5rs program.scm, and to run an r6rs Scheme program:
At the moment, there doesn't seem to be an
r7rs language included by default, but there exist third-party modules implementing r7rs-small. This situation may change in the future.