[plt-scheme] eval and phases (v4.0.1.2)

From: Sam TH (samth at ccs.neu.edu)
Date: Thu Jun 26 15:49:34 EDT 2008

On Wed, Jun 25, 2008 at 2:55 PM, Matthew Flatt <mflatt at cs.utah.edu> wrote:
> As of version (now in SVN):
>  1. Each namespace has a "base phase" that is used by `eval',
>    `dynamic-require', etc., instead of always starting in phase 0.
>  2. While compile-time expressions are evaluated (such as the body of a
>    macro transformer or the right-hand side of `define-for-syntax'),
>    the current namespace is set to one whose base phase matches the
>    evaluation phase.

I have a couple issues with this.  First, the following seems like a
bug.  If you put this module in the Module language, and hit run:

#lang scheme/base
(require (for-syntax scheme/base)
         (for-template scheme/base))

(define-namespace-anchor anch)

;; local-expand and then typecheck an expression
(define-syntax (tc-expr/expand stx)
  (syntax-case stx ()
    [(_ e)
     #`(parameterize ([current-namespace (namespace-anchor->namespace anch)])
         (let ([ex (expand 'e)])
           (syntax->datum ex)))]))

and then enter this at the REPL:

(tc-expr/expand (+ 3 3))

you get the result:

(#%app + '3 '3)

as expected.

If you put the call in the definitions window instead, you get this error:

compile: bad syntax; function application is not allowed, because no
#%app syntax transformer is bound in: (+ 3 3)

This discrepancy seems problematic.

Second, in the new regime, how can I accomplish what this macro is
trying to do, since the current version no longer works?

sam th
samth at ccs.neu.edu

Posted on the users mailing list.