5

One of my courses is using DrRacket for some sections of SICP. We're working on the metacircular evaluator and I have an R5RS code file (set-car! and set-cdr!) which I need to use with my work. Because the R5RS file is roughly 500 lines, I'd prefer to keep it in a separate buffer. How can I include it into my answer buffer's defintions? It appears racket/include requires #lang racket, but set-car! and set-cdr! are not in that language.

Sam Tobin-Hochstadt
  • 4,983
  • 1
  • 21
  • 43
Kizaru
  • 2,443
  • 3
  • 24
  • 39

1 Answers1

10

You can do the following:

  1. Write the module in #lang r5rs, and add the following after the lang line:

    (#%provide (all-defined))
    
  2. Have your answer buffer also in #lang r5rs, and use #%require to pull in its definitions:

    (#%require "some-module.ss")
    

For example, if I have an f1.ss with the following content:

#lang r5rs
(#%provide (all-defined))
(define (f x)
  (* x x))

and an f2.ss with the following content:

#lang r5rs
(#%require "f1.ss")
(display (f 3))
(display (f 4))

then if I run f2.ss, it does the appropriate thing in displaying 916, and its Interactions buffer will know about all the definitions written in f1.ss.

This uses the Racket-specfic low-level module importing stuff mentioned in the documentation. Good luck!

dyoo
  • 11,795
  • 1
  • 34
  • 44