Email list hosting service & mailing list manager


Re: Namespaces Martin Gasbichler 16 Aug 2005 12:37 UTC

Matthias Neubauer <xxxxxx@informatik.uni-freiburg.de> writes:

> Matthias Neubauer <xxxxxx@informatik.uni-freiburg.de> writes:
>
> Argh! I guess I got the stages wrong. Macros are more like ...
>
>
> # let prog = .< let x = 1 in
>               .~ (let m () = let x = 2 in
>                              .< x >.
>                   in m ()) >.;;
>       val prog : ('a, int) code = .<let x_2 = 1 in 2>.
> # let res = .! prog;;
> val res : int = 2
> #
>
>
> ... I guess.

That's still bogus because the macro application happens within the
same expression as the binding of the macro. The following looks more
appropriate:

# let prog = .< let x = 1 in
              .~ (let m () = let x = 2 in
                             .< x >.
                  in
                   .< .~ (m ()) >.) >.;;

> Cross-stage persistence still kicks into action, though.

But you don't need it because a macro is a source-to-source
transformation and UNQUOTE (as SRFI-72 and MetaOCaml provide it)
already does the trick:

let prog = .< let x = 1 in
              .~ (let m () = let x = .< 2 >. in
                             .< .~ x >.
                  in
                   .< .~ (m ()) >.) >.;;

Note that syntax-case also doesn't allow you to use bindings from the
meta-level within SYNTAX terms but provides a special abstraction for
this task: pattern variables.

--
Martin