Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Including an r5rs file into another file in racket

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.

like image 381
Kizaru Avatar asked Nov 28 '11 03:11

Kizaru


1 Answers

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!

like image 189
dyoo Avatar answered Sep 24 '22 00:09

dyoo