MOLD/ONLY vs. MOLD SPREAD

Historically, the way you would ask to mold an array without its delimiters was with MOLD/ONLY:

rebol2>> mold [a b c]
== "[a b c]"

rebol2>> mold/only [a b c]
== "a b c" 

In Ren-C this raises some existential questions, like how should quoted arrays be handled?

mold/only first [''(a b c) d e]  ; ???

But I think there's a better answer: use SPREAD and splice isotopes. If you want to mold the contents of an array, then turning it into a splice seems the natural answer. And since you can't have splices of quoted things...there's a nice unambiguous answer.

>> mold [a b c]
== "[a b c]"

>> mold spread [a b c]
== "a b c"

It does raise the question of what to do if you have something that might be an array or might not. How do you tell it to mold as is if it's not an array, or without the delimiters if it is? That's what MOLD/ONLY did, after all:

rebol2>> mold/only [b l o c k]
== "b l o c k"

rebol2>> mold/only <tag>
== "<tag>"

"SPREAD won't SPREAD tags..." you say. And no, it won't. But I think this is a rare case... and the neat thing about putting the bit on the value (as opposed to a refinement) is you can make functions like SPREAD-OR-AS-IS. Or SPREAD-IF-PATH-OR-GROUP. You can really tweak this however you want.

>> mold spread-or-as-is <tag>
== "<tag>"

>> mold spread-or-as-is "[b l o c k]"
== "b l o c k"

>> spread-if-path-or-group 'p/a/t/h
== ~(p a t h)~  ; isotope

>> mold spread-if-path-or-group 'p/a/t/h
== "p a t h"

How about THAT? All of this hinges on the idea that MOLD doesn't generally know how to mold isotopes, as they have no representation. It just chooses to interpret the request to mold a splice isotope as "contents matter, no delimiters".

More control, more clarity, and the death of another /ONLY. What more could you ask for?

1 Like