[racket] eginner's question on elementary textual replacement...

From: Rüdiger Asche (rac at ruediger-asche.de)
Date: Sun Mar 11 17:00:52 EDT 2012

> Hello,
> in most cases you should probably simply use a regular definition like
> this:
>  (define ONE 1)
> If that definition is not exported from the module you are writing it
> will probably be inlined anyway.

This doesn't appear to be true. You probably refer to this snippet of the 
docs here:


which reads that in a liberal expansion context (which is implied in 
modules) define may translate to define-syntax. However:

(require macro-debugger/stepper-text)
#'(module alias racket
   (provide plusone)
   (define ONE 1)
   (define (plusone x) (+ x ONE))
   (plusone 2)

  (#%provide:3 (expand:3 (provide-trampoline:3 plusone)))
  (define-values:7 (ONE) (quote 1))
  (define-values:13 (plusone) (lambda:12 (x) (#%app:17 + x ONE)))
   (lambda:16 () (#%app:15 plusone (quote 2)))

which generates a binding (albeit a define-values which according to the 
docs is also possible).

> If you really want a syntactic replacement, syntax-id-rules could be
> what you are looking for:
>  (define-syntax ONE (syntax-id-rules () [ONE 1]))

This yields the expected result:

(require macro-debugger/stepper-text)
#'(let ()
 (define-syntax alias
                    (syntax-rules ()
                     [(_ symbol literal)
                        (define-syntax symbol (syntax-id-rules () [symbol 
  (alias ONE 1)
  (define (plusone x) (+ x ONE))
  (plusone 2)

  (((plusone) (lambda:27 (x) (#%app:30 + x '1))))
  (#%app:32 plusone (quote 2))))

So what made you think that defines within modules are inlined? Is it a doc 
bug, or were you looking at something else than liberal expansion that needs 
additional work? What does it take for define to translate into 
define-syntax within a liberal expansion context?


Posted on the users mailing list.