[racket] eginner's question on elementary textual replacement...
If you're interested in the compilation that happens after macro
expansion, including constant-propagation and inlining, then try `raco
make' and `raco decompile'.
For example, if "alias.rkt" has
(module alias racket
(provide plusone)
(define ONE 1)
(define (plusone x) (+ x ONE))
(plusone 2))
then `raco make alias.rkt' followed by `raco decompile alias.rkt' shows
(begin
(module alias ....
(define-values (_ONE) '1)
(define-values
(_plusone)
(begin
'%%inline-variant%%
(#%closed
plusone9
(lambda (arg0-10)
'#(plusone #<path:/private/tmp/alias.rkt> 4 3 65 30 #f)
'(flags: preserves-marks single-result)
(#%in + arg0-10 '1)))
(#%closed
plusone8
(lambda (arg0-13)
'#(plusone #<path:/private/tmp/alias.rkt> 4 3 65 30 #f)
'(flags: preserves-marks single-result)
(#%in + arg0-13 '1)))))
(#%apply-values |_print-values@(lib "racket/private/modbeg.rkt")| '3)))
There's a lot of noise in the output, but the main result is the `3' in
the last line that is printed as the result value --- which shows that
`(plusone 2)' was reduced to `3' at compile time.
At Sun, 11 Mar 2012 16:17:43 -0500, Robby Findler wrote:
> Yes, that is correct. Macro expansion happens before any of the
> optimization steps performed by the compiler.
>
> Robby
>
> On Sun, Mar 11, 2012 at 4:06 PM, Thomas Chust <chust at web.de> wrote:
> > On Sun, 2012-03-11 at 22:00 +0100, Rüdiger Asche wrote:
> >> [...]
> >> 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?
> >> [...]
> >
> > Hello,
> >
> > section 18 of the Racket guide suggests to me that module local bindings
> > which are not exported, not mutated and have sufficiently simple values
> > will be inlined. This is something that will happen in the bytecode
> > compilation or JIT compilation stages, after macro expansion has already
> > taken place, so I don't think you will see it in the macro stepper.
> >
> > However, I'm no expert concerning the internals of Racket's compiler and
> > I may be mistaken here.
> >
> > Ciao,
> > Thomas
> >
> >
> > --
> > When C++ is your hammer, every problem looks like your thumb.
> >
> >
> > ____________________
> > Racket Users list:
> > http://lists.racket-lang.org/users
>
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users