[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Namespaces



Matthias Neubauer <neubauer@xxxxxxxxxxxxxxxxxxxxxxxxxx> writes:

> Matthias Neubauer <neubauer@xxxxxxxxxxxxxxxxxxxxxxxxxx> 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