masak / alma

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

Throw a compiler error when a macro parameter is unquoted more than once in a quasi #234

Open masak opened 7 years ago

masak commented 7 years ago

We're talking about this situation, as seen in #214:

quasi {
    {{{it}}} = {{{it}}} * 2;
}

The same comment in that issue also coins the Single Evaluation Rule: if a quasi unquotes the same AST fragment more than once, it's more likely than not to be a thinko.

(Why? Because in the end, it seems to be a blind spot for macro authors — at least for me — that it above might involve a side effect, and by duplicating it we're also duplicating the side effect.)

We can trivially detect this; at least we can trivially detect when the same variable is unquoted more than once in a quasi — which is probably good enough. If we can then make the error message nice and friendly, this ought to be a win. Maybe the error message should mention the is lazy @succinct trait, which allows a developer to keep not caring about duplicated side effects.

masak commented 7 years ago

There also needs to be a way to suppress the error message — simply because language designers are not omniscient, and might overlook a genuine need by a macro author.

At worst, I could imagine suppressing the error message through a macro trait. Maybe there's some nicer way.

masak commented 6 years ago

There is a nicer way. We can mark parameters and local variables with is thunky or @Thunky if we want to suppress the error.