All-SPLICE!: REDUCE, DELIMIT (SPACED, MOLD...)

On The Theme of ALL-SPLICE!...

Historically I discouraged the idea of "too many functions taking splices".

One good reason would be that SPLICE! carries no binding.

Hence if you were going to do this:

>> reduce ~[1000 + 20 300 + 4]~
== \~[1020 304]~\  ; antiform (splice!)

Then REDUCE would have to assume you wanted the binding from the callsite (the way COMPOSE does by default).

Today's REDUCE uses the binding of the thing you pass it... and I think NOT using the binding of the callsite should be the overwhelming default for functions.

But... COMPOSE is different. It can operate on unbound material (strings, even!) (or: "strings, especially!!!")

So is there any good reason to prohibit it for COMPOSE?

:thinking:

I was looking at this piece of the implementation of the SOURCE function:

    keep opt spread compose [
        return: (conditional ret.spec)
    ]

    for-each [key param] f [
        keep spread compose [
            (decorate param key) (opt param.spec)
                (opt param.text)
        ]
    ]

And I thought "that gets tighter if I could use a SPLICE!"

    keep opt compose ~[
        return: (conditional ret.spec)
    ]~

    for-each [key param] f [
        keep compose ~[
            (decorate param key) (opt param.spec)
                (opt param.text)
        ]~
    ]

Is that so wrong?

I think it makes things more obvious... you can look at it from a few feet away and go "oh yeah, a splice!"

It's also more performant. You duck a function call to SPREAD.

Will People Start Expecting This?

I get a bit worried about people failing to grasp the nuance of why COMPOSE can do it, and REDUCE can't.

And it seems like it could open the floodgates to questions like "should JOIN take splices?"

>> join ~[a b c]~ [1000 + 20 300 + 4]
== \~[a b c 1020 304]~\  ; antiform (splice!)

How about FIND? Does SPLICE! have a position... is it a series?

As useful as these things may seem, I have a sneaking suspicion that they're a bad idea. You start to lose grounding pretty quickly. (I've explained why I don't think QUOTED! or QUASIFORM! etc. type things should be supported by generic operations.)

I Think It's Okay For COMPOSE

COMPOSE may be an odd one out, because it's a templating thing. Something about its nature may just be more suited to "I work in whatever skeleton you gave me."

Certainly I'd use it.

1 Like