Can templates and macros be replaced by BaseLanguage expressions and quotations? Follow
Learning MPS involves learning a lot of new concepts. I find templates and their macro language especially arcane. I keep wondering whether the added complexity of templates and macros is essential.
I see a generator as a function
node<A> -> node<B>
Wouldn't it be possible to specify such generators as functions in BaseLanguage, taking advantage of quotations where appropriate? That would decrease the number of new concepts/languages that language developers have to learn.
Please sign in to leave a comment.
Indeed, a template language based purely on functions (e.g. BaseLanguage functions) is feasible for certain scenarios. Present MPS template language was designed to be a bit declarative (though there are queries that are BL functions due to historical reasons). You can 'simulate' pure functional generator with a reduction rule (for concept A) that has $INCLUDE$ macro rhs, with query function to build a node (of concept B). I'm pretty sure you gonna face limitations of functional approach in some scenarios as well, as there's no single 'right' choice for a template language. With MPS, however, you can use whatever transformation language you like (e.g. j.mps.lang.generator is just a regular language), and with some effort you may use your transformation language of choice for 'Make' action as well (with a custom make facet).
Thanks for your answer! I'm going to explore these possibilities next time I need to write a generator. The first approach, to put the implementation in $INCLUDE$ macro's query function, will hide the whole implementation inside the inspector, which is not ideal, but good for testing the functional approach. The second approach, configuring a custom transformation language, seems like a more principled solution.