It's Time To JOIN Together


#1

There’s been a tremendous amount of learning and good artifacts which have come out of not taking REJOIN/JOIN for granted. As @Brett’s critique pointed out, REJOIN sucked, and we now have much more palatable options and strategies…most notably DELIMIT+SPACED+UNSPACED, which have become nicely defined foundations for one’s daily string work…doing the right kind of merging and null/blank handling, splicing single characters without delimiting, etc.

My initial impressions from the names were that JOIN and REJOIN were integrally linked, and so JOIN got kind of a bad reputation from that. JOIN was a “copies its first argument” variant of “REPEND” (one of the badly named functions with REFORM and REMOLD). In a system that mutates by default, I wondered if this should be flipped, and JOIN would be REPEND with a non-mutable variant (JOIN-OF?)

Nice try, but it’s time to move JOIN-OF back to JOIN

No grand new generalization ever gel’d together. Ideas like making non-mutating forms of all the operators be named things like APPEND-OF and JOIN-OF were overshadowed by the OF reflector gaining central prominence for that meaning (LENGTH OF BLOCK). What we really probably just need are system internals for optimizing patterns like append copy block ... so that the append and copy can merge together internally in one pass, and I have ideas on how that can work.

But besides nothing better emerging, NewPath has brought an issue to the forefront previously only hidden in TUPLE!s: immutable paths have the need for a fundamental non-mutating operator to add stuff to them. You can’t just say that JOIN takes a PATH!, copies it, and appends to it…because PATH!s no longer allow mutation. COPY is a no-op on them, and the APPEND will fail with an invalid type error (it’s an ANY-PATH! which now lacks a position…hence not an ANY-SERIES!, and it’s immutable, where APPEND expects mutability).

JOIN is thus distinct from the mutable world that APPEND lives in. It’s its own thing.

And I don’t think anyone is going to be upset seeing a Rebol2-compatible JOIN come back.

Easy impact to absorb…

The JOIN-OF synonym can stay working for a while, but ultimately it will be phased out. Like I said above, OF has fit in nicely with a new purpose.

There are a few JOINs out there that have been introduced trying out a life as the “new REPEND”. (I’m probably the only one who did so.) But if you did this, then rather than replacing those with REPEND, please just change them to append x reduce […]. Many cases of that pattern are about to get more efficient, and as I mentioned there are some internal ideas on folding these kind of operators together inside the evaluator.