masak / alma

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

Two Qtrees evaluated from the same quasi but different macro invocations should compare unequal #544

Open masak opened 5 years ago

masak commented 5 years ago

Haven't checked this, but I have a feeling the following fails:

BEGIN my qs = [];

macro moo() {
    my x;
    my q = quasi {
        say(x);
    };
    qs.push(q);
    return q;
}

moo();
moo();

BEGIN say(qs[0] != qs[1]);

That is... there's only one variable x in the script, and of the two injectiles generated, they will be indistinguishable in structure and behavior (they'll both print none and a newline), but the two injectiles do differ in that they're locked onto different x locations. (And that difference matters.)

(So the code ought to output true none none on separate lines.)

Again, I haven't run the code above, but I have a sneaking suspicion we're not distinguishing. We should be.

Even if we accidentally get this one right, it deserves to be turned into a test.

masak commented 5 years ago

Indeed. I ran the above, and:

false
none
none

It's a bug.

masak commented 5 years ago

In a way, I was right six-seven years ago when I said to @moritz++ that ASTs (Qtrees) close over their environment. The only refinement I would make to that today is that it's the individual variables (well, their Qnodes) that "close over" their environment — by binding direct to their (unique) memory location — and it only happens to variables bound outside the quasi.