# COLLECT Semantics: KEEP vs. KEEP SPREAD

**URL:** <https://revolt.metaeducation.com/forum/t/collect-semantics-keep-vs-keep-spread/1706>\
**Category:** Semantics\
**Created:** [September 5, 2021, 11:56am UTC](https://revolt.metaeducation.com/forum/t/collect-semantics-keep-vs-keep-spread/1706 "2021-09-05T11:56:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hostilefork](https://revolt.metaeducation.com/forum/user_avatar/revolt.metaeducation.com/hostilefork/32/421_2.png) [@hostilefork](https://revolt.metaeducation.com/forum/u/hostilefork)\
**Post date:** [September 5, 2021, 11:56am UTC](https://revolt.metaeducation.com/forum/t/collect-semantics-keep-vs-keep-spread/1706/1 "2021-09-05T11:56:38Z")

</div>

When reimplementing COLLECT for UPARSE on top of the "pending" model, [I mentioned a potential avenue for optimization](https://revolt.metaeducation.com/forum/t/getting-hooks-into-events-during-parse/1640/10) by not immediately splicing blocks, but keeping them in a list and then merging the whole list together if-and-when the COLLECT got to the success point:

> [@MAXMATCH Parser Combinator, With/Without Rollback!](https://revolt.metaeducation.com/forum/t/maxmatch-parser-combinator-with-without-rollback/2648/3):
>
> (Efficiency sidenote: I might should have used something like @[...] blocks for GATHER, and use BLOCK!s for KEEP to complement the QUOTED!s. This would save splicing until the very end COLLECT when you have a better idea of how big the total series will be.)

The idea of saving splicing until the end might sound good, but... it doesn't work if we presume mutations.

Just imagine a delaying implementation of ordinary COLLECT:

```
>> delayed-splice-collect [
      block: [a b c]
      keep spread block
      clear block
      insert block [d e f]
      keep spread block
  ]
== [d e f d e f]

```

That's not what we expect from today's COLLECT.

Though if you're _not_ splicing, you expect mutations to affect what you've already collected. It's true in all Redbols today, since you're keeping the block by identity:

```
red>> collect [
         block: [a b c]
         keep block
         clear block
         insert block [d e f]
         keep block
      ]
== [[d e f] [d e f]]

```

## [Persistent Vector](https://hypirion.com/musings/understanding-persistent-vector-pt-1) Looks Awfully Tempting 🧐

Looking at things like this is always a throwback to saying _"mutable state by default is garbage"_. But it depends on what example you're looking at. Sometimes it's good, sometimes it's bad.

I guess the thing is to just explore what the good parts are. Maybe someone (or some AI) will blend in some Clojure bits at some point in a derivative...but that person (or AI) is not going to be me!

---

<div class="post-metadata">

**Author:** ![hostilefork](https://revolt.metaeducation.com/forum/user_avatar/revolt.metaeducation.com/hostilefork/32/421_2.png) [@hostilefork](https://revolt.metaeducation.com/forum/u/hostilefork)\
**Post date:** [January 14, 2026, 8:03am UTC](https://revolt.metaeducation.com/forum/t/collect-semantics-keep-vs-keep-spread/1706/2 "2026-01-14T08:03:29Z")

</div>

> [@hostilefork](#):
>
> The idea of saving splicing until the end might sound good, but... it doesn't work if we presume mutations.
> 
> Just imagine a delaying implementation of ordinary COLLECT:
> 
> ```plaintext
> >> delayed-splice-collect [
> block: [a b c]
> keep spread block
> clear block
> insert block [d e f]
> keep spread block
> ]
> == [d e f d e f]
> 
> ```

**There are several good reasons for SPLICE! to be immutable, and this is one of them.**

Outside of the benefits for COLLECT in PARSE, it makes the immutability of NONE seem less random... you just take for granted that _all_ splices are immutable.

This would mean that if you SPREAD something, it becomes shallow-locked. If that's not what you want, it's your responsibility to shallow copy it.

It's not particularly oppressive for the existing uses, most of which are just **spread compose [...]** or **spread reduce [...]** anyway. And SPLICE isn't meant to be passed to the first argument of things like APPEND anyway.
