On Wed, Sep 12, 2018 at 4:49 PM Wojciech S. Czarnecki <o...@fairbe.org> wrote:
> > This is not metaprogramming! > > Every and each statement is written by the human author in plain Go > and no code is produced by the program itself. > > The key of metaprogramming is the ability to treat code as data which can be manipulated. That is, it gives you access to some form of the AST of the program in question which you can manipulate at compile time. If you forgo the principle of treating code as data, then you end up with a definition in which every compiler is metaprogramming, insofar it produces code based on code. I'll refrain from judging if this or that is metaprogramming, but the code-as-data principle tends to be a non-negotiable property to most people I think. In some languages, the '<' operator can be given new instances of implementation such that the Less method isn't needed. This circumvents much of the challenge originally posed. Haskell is one such language, and I believe this is also possible in C++ though my C++ is rusty to put it fairly. The other solution is to force the programmer to provide a signature of the required form, so in the case you have to write a Less method which uses '<' internally, in turn making operator fit the signature of the scheme you have. This is used by OCaml. It is worthwhile to add to the discussion that you can have this implicit or explicit. In the structural or implicit variant, the compiler figures out what you want and picks the correct instance at compile time. In the nominal or explicit variant, the programmer provides the implementation they want. An important subtlety is that if we are using the implicit variant, then there can be no ambiguity in the choice. There can only be one Less for a type so to speak. In the explicit case, we can have several Less orderings and choose among them as programmers. But we also require more programmer cognitive load while doing so. -- 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.