Coder Social home page Coder Social logo

MOP _и_ AST? Por que los dos? about alma HOT 3 OPEN

masak avatar masak commented on August 16, 2024
MOP _и_ AST? Por que los dos?

from alma.

Comments (3)

masak avatar masak commented on August 16, 2024

As time passes, I find myself leaning more and more strongly towards "they should both exist, and be separate".

I have two new pieces of evidence, for some very loose definition of "evidence":

  • Swift macros. I'd need a lot more time and headspace to be able to state clearly what I think is great about them, but... one thing they do well is to (it seems to me) interact with class declarations and their members. While this could still be phrased directly in terms of ASTs (and maybe it is?) the amazing difference compared to Lisp- and Scheme-like macros is that it doesn't feel like we're working on just syntax anymore; we're working with full awareness of the declaration structure of, say, a class declaration.

  • Herb Sutter's proposed C++ metaclasses (later renamed to metafunctions, if I understood it right in that keynote). The API here seems like it's in dialogue with a set of "mirror"-like objects, and something like t.add_virtual_destructor(); seems to me to be quite high-level and no longer just AST.

from alma.

vendethiel avatar vendethiel commented on August 16, 2024

I think it's impossible to have a discussion about this without talking about phases and binding times.
What can you see, when? Do macros and classes "appear" into existence at the same time?
If macros were only concerned with syntax and parsing, they'd be considered before any kind of analysis, and classes would just be a node amongst others.
If you consider that macros need to be able to interact with the MOP, you need to interleave both, but how isn't always obvious.

If you have a macro call inside of a class, should it be able to retrieve said class? Either by name or by "surrounding context"? In that case, what should the class look like? A stub, hole-y node, waiting to be completed? (that actually sounds like a quote if you get very very very creative, because it has a hole and because it shouldn't appear in the final AST).

On the other hand, if you collect macros inside of the class body and delay them (that is, after the initial declaration but before "sealing" or - to reuse Raku vocab - "composing" the class) to run them all at once, you might be able to provide a more sensible view of the class.

Early-binding languages and mop<=>macros interactions is not something that's well-researched, I think, and it kind of shows.

from alma.

masak avatar masak commented on August 16, 2024

I think it's impossible to have a discussion about this without talking about phases and binding times.
What can you see, when? Do macros and classes "appear" into existence at the same time?

I think this is the right way to approach the whole thing, yes.

I hereby declare my intention to review a few languages from the above perspective — what can you see, when? — in order to shake out some understanding from that about what modern languages actually do.

My candidate languages will be: Java, Perl 5, Raku, Python, and CLOS. The focus will be on the object metamodel, and at which exact point during the compilation process it becomes accessible.

from alma.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.