On Fri, 14 Dec 2018 at 05:25, Dmitry Ponyatov <dponya...@gmail.com> wrote:

> Is it possible to do metaprogramming in Go?
>
> What I want to have is a way to run arbitrary code in compile time, which
> has full access to compiler data structures
> (parsed syntax trees, compiler stages callbacks, direct code generator
> calls).
>
> As a variant, it can be some Lisp system runs between parser stage and the
> rest of  Go compiler.
>

To answer your original question, yes, it is possible to do metaprogramming
in Go, although not at compile time.

That's essentially what the go generate command is about - a command run by
go generate has access to parsed syntax trees, type information and
anything else it likes (bar actual compiler internals), and can generate
whatever code it likes.

For example, I think it's pretty clear that what the Wire project does (see
https://github.com/google/wire/blob/master/docs/guide.md) is
metaprogramming, to some degree or other.

  cheers,
    rog.

> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to