masak / alma

ALgoloid with MAcros -- a language with Algol-family syntax where macros take center stage
Artistic License 2.0
138 stars 15 forks source link

plforums.org "I will invite them here if anyone replies." #305

Closed raiph closed 6 years ago

raiph commented 6 years ago

Please see https://plforums.org/practice/an-algoloid-that-uses-macros-to-define-itself#post_69

Feel free to close this issue at any time.

masak commented 6 years ago

I haven't understood the goal about "using macros to define itself", though I admit I haven't read linked threads in detail. What exactly would be the difference from usual boostrapping?

Bootstrapping can certainly be done without macros. The very small metacircular evaluator in "The Roots of Lisp" is an example. I imagine 007 could also be bootstrapped (including macros) without using macros.

Given that macros are essentially there as a way to extend the parser, though, it makes sense to also use them in the implementing language (if that happens to be 007-with-macros). It's not macros' primary purpose to serve in bootstrapping, they might just occasionally be the right tool.

masak commented 6 years ago

@raiph I just saw your reply over at the other link. Not sure you misunderstood things as much as you think. (Then again, all of this comes down to arbitrary definitions in the end. I'm still learning what exactly constitutes "meta-circular", "bootstrapping", etc.)

My decision to reply here rather than on the plforums.org site was based on convenience more than anything else. :smile: It looked like I'd have to create an account (yet another one), and I wanted to get as quickly to the point of writing a reply as I could.

Fwiw, I do want to define all the built-in statement forms as macros. Thinking about this recently has made me realize that we definitely need an is qtype trait as described in https://github.com/masak/007/issues/163#issuecomment-238338664 — though my thinking about this has developed some and I would nowadays write that as a function facade that wraps the quasi and I should totally open a new issue about that — note to self.

Why is this important if we use macros for all the built-in statements? Because we've already decided, long ago, that Q::Statement::If is what ends up in the program qtree. The is qtype/facade would be what fulfills that promise, whereas the quasi would contain the under-the-hood implementation of an if statement. In other words, if everything built-in has an underlying implementation, then it becomes all the more important to hide that implementation behind a veneer of respec^Waxiomaticity.

But I'm a little bit concerned that by definition, 007 is no longer (aiming to be) "meta-circular". So far, we've run our 007 code by interpreting the AST. We won't do that much longer, I think. Instead everything compiled will be written to a backend. By default, 007 will have a runtime of its own, largely inspired by Python's (but also borroing from JVM, v8, wasm, and others). My idea for how to implement Q::Statement::If is then "it code-generates the right instructions with jumps and labels" (see https://github.com/masak/007/issues/145#issuecomment-368418062 for early thoughts on this). Even if the runtime ends up being implemented in 007 as well, I'm not sure this counts as being a meta-circular evaluator anymore. (At most, it's a "mutually-metacircular compiler/runtime", I guess.) It's definitely still bootstrapping, though.