2

I am learning scheme and working with the metacircular interpreter for examples and practice, and I am getting the following error:

 set-car!: unbound identifier in module in: set-car!

And the error is being caused by the following code:

(define (add-binding-to-frame! var val frame)
  (set-car! frame (cons var (car frame)))
  (set-cdr! frame (cons val (cdr frame))))

I have two questions... First, what does the error mean? And secondly, am I missing a let function?

choloboy
  • 795
  • 4
  • 16
  • 38

1 Answers1

2

In Racket a pair allocated by cons is immutable by design - therefore there are no set-car!. To allocated a mutable pair, use mcons. To mutate a mutable pair, use set-mcar! and set-mcdr!.

Here is a complete program:

#lang racket
(define p (mcons 1 2))
(set-mcar! p 3)
p
soegaard
  • 30,661
  • 4
  • 57
  • 106
  • Made the appropriate changes, and I still get the same error. Thank you for the answer though. – choloboy Nov 21 '14 at 18:52
  • 1
    I have added a complete program. Note that mcons, mcar, mcdr, set-mcar! and set-mcdr are exported by racket/base. Use (require (only-in racket/base mcons mcar mcdr set-mcar! set-mcdr!)) if you are using a language, where the mutable versions aren't included from the start. – soegaard Nov 21 '14 at 18:58