lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]




On Mon, May 2, 2011 at 8:59 AM, steve donovan <steve.j.donovan@gmail.com> wrote:
On Sun, May 1, 2011 at 11:36 PM, Alexander Gladysh <agladysh@gmail.com> wrote:
> https://github.com/bartbes/Meta/blob/master/meta.lua#L32

I like this idea - so (for instance) mod.m.lua would be preprocessed
with a specific set of macros when loaded with require("mod").

It has the interest of being conceptually simple, and it should be easy to hack simple syntax tweaks based on this. Hacking on strings is simple, because strings are a simple and well-known data structure. The price you pay is, it's really hard to get anything that really works: confidence-inspiring, with no corner case failure or weird limitation, modular and playing well with other extensions, which produces clear error messages when users make a syntax error, and which respects runtime debug info such as line numbers.

Programs can be seen at different structuring level: strings, token streams, parse trees, abstract trees. The less structured the approach, the easier it is to do a quick and dirty job; the more structured approaches allow to write something correct, but generally have a steeper learning curve.

I wonder how useful the quick&dirty option is. I would think that new syntaxes are mainly intended to ease maintenance and readability, but I fear that the brittleness inherent to low level approaches more than outweigh any gain. How much confidence would you put in code that's rewritten by half a dozen preprocessor macros, which don't even have a way to express the notion of scope? How confident would you be, when facing a weird bug, that the problem is in your code and not in some nasty interaction between a couple of preprocessor macros? When you suspect it is indeed such an interaction, are you willing to spend days understanding all the macros in detail, then refactoring them in depth to fix the problem? Or will you just give up the syntax sugar they allowed you to use?

Having done a fair share of LaTeX macro "programming", and having committed a couple of m4-based crimes against good taste, I know I can't feel confident with hacked-together macro systems. Every other bug turns into a nightmare, digging into poorly maintained macro packages. It is barely bearable for a text processor, I'd never accept to debug a realistic program in such conditions.