# Working through SICP in Jupyter Notebooks

By Corey J. Gallon · 2024-10-06 · https://gallon.me/working-through-sicp-in-jupyter-notebooks.html

---

I’m reading Structure and Interpretation of Computer Programs and want to write Racket in VSCode in Jupyter notebooks in a dialect of Scheme closest to the book.  This requires this declaration at the top of each Racket file:

```racket
#lang r5rs
```

HOWEVER, Jupyter doesn’t like this …

![Jupyter Doesn't Like This](https://gallon.me/images/20241006_jupyter_doesnt_like_this.png)

The Jupyter kernel for Racket doesn't directly support changing the language with `#lang` declarations in individual cells.  Claude to the rescue, though … eventually … what a pain to finally get to this!

1. We need to find our where `iracket` is installed.
    
```bash
❯ find ~/.local -name iracket.rkt
/home/captivus/.local/share/racket/8.2/pkgs/iracket/iracket.rkt
```

2. Now, we edit this file (`home/captivus/.local/share/racket/8.2/pkgs/iracket/iracket.rkt`**)** as follows:
    
```racket
#lang racket/base

;; ============================================================
;; Enabling R5RS mode for compatibility with SICP code
(require racket/sandbox)

(define orig-current-namespace (current-namespace))
(define r5rs-namespace (make-base-namespace))
(parameterize ([current-namespace r5rs-namespace])
  (namespace-require 'r5rs))

(define (switch-to-r5rs)
  (current-namespace r5rs-namespace))

(define (switch-to-orig)
  (current-namespace orig-current-namespace))

(switch-to-r5rs)

;; The rest of the original iracket.rkt content should follow here ...
;; ============================================================
```
    
3. Now, restart your VSCode and create a Jupyter notebook as previously described in your TIL article … and you’re up!
