The SPLIT function has... a lot of potential things you can split by:
>> help split
USAGE:
SPLIT series dlm :into
DESCRIPTION:
Split series in pieces: fixed/variable size, fixed number, or delimited
RETURNS: [<null> block!]
ARGUMENTS:
series [any-series?]
dlm [
<opt> "just return input in a 1-element block"
block! "parse rule"
@block! "list of integers for piece lengths"
integer! "length of pieces (or number of pieces if :INTO)"
bitset! "set of characters to split by"
char? text! "text to split by"
quoted! "literally look for value"
splice! "split on a splice's literal contents"
]
REFINEMENTS:
:into
If dlm is integer, split in n pieces (vs. pieces of length n)
Lots of design questions, there...
But I want to draw attention to [quoted! splice!], specifically.
The idea here is that you can split a list up based on literal values:
>> split [a b c * x y * z * * m n o] the '*
== [[a b c] [x y] [z] [] [m n o]]
Why does it use a QUOTED! for a literal value? Well, because if it didn't we couldn't split based on any of the things that already have meaning... like INTEGER! or BLOCK!
>> split [a b c 3 x y 3 z 3 3 m n o] the '3
== [[a b c] [x y] [z] [] [m n o]]
>> split [a b c [?] x y [?] z [?] [?] m n o] the '[?]
== [[a b c] [x y] [z] [] [m n o]]
And of course, since it generalizes it generalizes to quoted things, but you have to mentally subtract a quote level there as well:
>> split [a b c '@ x y '@ z '@ '@ m n o] the ''@
== [[a b c] [x y] [z] [] [m n o]]
If we weren't using THE, you'd have to do even more quoting math on the quote:
>> split [a b c '@ x y '@ z '@ '@ m n o] '''@
== [[a b c] [x y] [z] [] [m n o]]
- The first quote suppresses the evaluation to pass in the double quoted thing to SPLIT
- The second quote tells SPLIT you mean the unquoted thing is what you literally want to match
- The third quote is the "real" one you're looking to match literally on
Nifty SPLICE! Frees You From Mental Quoting Math
>> split [a b c 3 x y 3 z 3 3 m n o] ~[3]~
== [[a b c] [x y] [z] [] [m n o]]
>> split [a b c [?] x y [?] z [?] [?] m n o] ~[[?]]~
== [[a b c] [x y] [z] [] [m n o]]
>> split [a b c '@ x y '@ z '@ '@ m n o] ~['@]~
== [[a b c] [x y] [z] [] [m n o]]
...and it also generalizes to more than one item...
>> split [a b c $ * x y $ * z $ * $ * m n o] ~[$ *]~
== [[a b c] [x y] [z] [] [m n o]]
So when I look at that, it makes me think "Is there really a reason to offer both QUOTED! and SPLICE!?"
Might we bring back the fabled ONLY (or JUST?) for creating a singular SPLICE! ?
>> item: <*>
>> only item
== ~[<*>]~
You could use regular splice syntax as ~[foo]~ instead of the 'foo.
And if your value was in a variable, you'd use only var (or just var?) instead of quote var.
I Think I've Convinced Myself
![]()
Using SPLICE! to speak out of band about literal items--to push that out of band in dialecting instead of using QUOTED!--makes sense.
In this case in particular... since SPLICE has to be supported anyway. This is the meaning that a single-element splice would be forced to take.
It reduces the mental math, and also frees up QUOTED! to mean something else.