Louis Christopher    About    Archive    Feed    Search

Aspiring Polymath

Setting up DrRacket for SICP

Download and install DrRacket.

Follow the instructions to set up Scheme for SICP.

You should be good to go now but soon you will hit a roadblock. Often times, while working through the exercises you’ll find yourself wanting to create your own library of common functions. Doing this is slightly tricky to account for the modifications to DrRacket. Here’s how to do it.

Lets say you have a file called lib.scm:

#lang racket
(define (sq x) (* x x))
(define (cube x) (* x x x))
(provide (all-defined-out))

Let’s go over this, I have a file with some functions that I’d like to call elsewhere. The last line (provide (all-defined-out) is a method in Racket to make public all of the functions defined in the file. This method is only available in racket which is why we don’t use #lang sicp here.

Now, to use the above program in another file, let’s say test.scm just include the line (#%require <relative path to file>):

#lang sicp
(#%require "lib.scm")
(sq 5)

Sources

Scheme for SICP , StackOverflow

If you have any questions or comments, please post them below. If you liked this post, you can share it with your followers or follow me on Twitter!