((Doubled Groups)) as a Dialecting Tool

In trying to get COMPOSE to lose /ONLY, there was a time when it looked for doubled groups.

>> block: [a b c]

>> compose [(block) ((block))]
== [a b c [a b c]]

I liked it, and I said:

But I found concerns:

To be fair: it's hardly the only case where if you jump to conclusions on reading a few characters that you'll have problems because the code keeps going and may invalidate the assumptions you made by looking at those few characters. But it still wasn't perfect.

...and as it turned out, it was another one of those "close but no cigar" cases of wanting to mark the intent of splice specially, but using a mechanism that's not as good as splice isotopes!.

I think that doubled-up-groups are a neat example of a dialecting concept, where you might want to give that significance. It would certainly belong in the dialecting handbook (if we had one).

But in the COMPOSE case, we have a better option... compose [... (spread block) ...] (or another operator of your choice that produces block isotopes). And it's more fitting for the core, because it doesn't have the weakness mentioned above.


Not that it would be hard to write again, but here's the C code for detecting doubled groups!

INLINE bool Is_Any_Doubled_Group(NoQuote(const Cell*) group) {
    assert(Any_Group_Kind(Cell_Heart(group)));
    const Cell* tail;
    const Cell* inner = Cell_Array_At(&tail, group);
    if (inner + 1 != tail)  // should be exactly one item
        return false;
    return Is_Group(inner);  // if true, it's a ((...)) GROUP!
}
2 Likes