[racket] local-expand and stop-lists?

From: Danny Yoo (dyoo at cs.wpi.edu)
Date: Fri Aug 12 13:25:07 EDT 2011

I'm having some difficulty using local-expand with regards to stop
lists.  Here's what I'm trying:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; small-lang.rkt

#lang racket
(provide (except-out (all-from-out racket)
                     #%module-begin)
         (rename-out [my-module-begin module-begin]))
(provide lift-to-toplevel)

;; lift-to-toplevel is meant to cooperate with module-begin.
(define-syntax (lift-to-toplevel stx)
  (printf "lift to toplevel\n")
  #'(void))

(define-syntax (my-module-begin stx)
  (syntax-case stx ()
    [(_ body ...)
     (begin
       (printf "Expanding...\n")
       (let ([expanded-body
              (local-expand #'(#%module-begin body ...)
                            'module-begin
                            (list #'lift-to-toplevel))])
         (printf "expanded\n")
         expanded-body))]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

I'd like local-expand not to immediately expand out the use of
lift-to-toplevel, but as far as I can tell, it's expanding
immediately.  When I run a program like:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#lang s-exp "small-lang.rkt"
(printf "hello world\n")
(lift-to-toplevel (printf "ok!"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


I see the following content:

---------------------------------
Expanding...
lift to toplevel
expanded
hello world
---------------------------------

In which the first three lines are coming from compile-time, and I see
that my lift-to-toplevel macro is firing off, even though I placed it
in the stop-list of local-expand.


Posted on the users mailing list.