greghendershott/fear-of-macros

syntax-case: unbound identifier

bennn opened this issue · 1 comments

When I tried to compile the first example in Section 4 I got the error: syntax-case: unbound identifier in the transformer environment; also, no #%app syntax transformer is bound

To fix this, I added (require (for-syntax racket/base)) to the top of my file. (The corrected version is at the bottom of this issue.) Two questions:

  1. Is this the correct fix?
  2. Did I miss a pre-requisite explanation in the tutorial?

For reference, I'm using Racket 6.1.1.4

#lang racket/base

(require (for-syntax racket/base))
(define-syntax (our-if-using-syntax-case stx)
    (syntax-case stx ()
      [(_ condition true-expr false-expr)
       #'(cond [condition true-expr]
               [else false-expr])]))

(our-if-using-syntax-case #t "true" "false")

Good point!

The tutorial is assuming you're using the "normal", "default" #lang racket. In that case, racket/base is automatically required for-syntax.

However I should make this assumption explicit, and, I should explain the gotcha with #lang racket/base.

In particular, it's common to change a file from #lang racket to #lang racket/base, and start getting the error you got. In my experience that error message is really confusing and frustrating, if you don't already know what it means (and how would you know, at first).