[racket-dev] Phase distinctions and "compile: identifier used out of context"

From: Carl Eastlund (cce at ccs.neu.edu)
Date: Sat Jan 29 15:07:37 EST 2011

The following program binds => at both phase 0 (module-scoped macro)
and phase 1 (lexically-scoped value).  The use of the => macro at the
end expands into a recursive reference to =>, which in turn produces
the error "compile: identifier used out of context".  As I understand
it, this happens because the identifier => has been taken out of the
scope of its phase 1 binding.  However, it is being used here at phase
0.  I would much prefer if the expander simply ignored the phase 1
binding and carried out the recursive macro invocation.

Before I file this as a bug report, have I understood what's going on?
 Is there any reason this shouldn't or couldn't be fixed?

#lang racket

(define-syntax =>
  (let ()
    (define (=> stx)
      (syntax-case stx ()
        [(_ result) #'result]
        [(_ hyp hyps ... result)
         #'(if hyp
             (=> hyps ... result)
             #t)]))
    =>))

(=> (odd? 1) (odd? 3) (even? (+ 1 3)))

Carl Eastlund


Posted on the dev mailing list.