Complexity of seq & related patterns
Wolfgang Corcoran-Mathe 05 Nov 2025 19:36 UTC
Hi dpk & the SRFI 262 list,
This SRFI spends quite a few words describing 'seq', 'seq*', and
'seq/unordered'. The syntax & semantics of these patterns far
exceeds the other patterns in complexity. To me they are also the
least familiar parts of the language, since there seems to be nothing
comparable in other pattern-matching systems.
There is something Rube Goldbergian about a syntax ('seq') that
combines a looping construct with a pattern that can match either
a single value or a subset of the sequence produced by the loop.
Pattern-matching is timeless, at least conceptually, but iteration
is, well, iterative, happening through time. Repeatedly generating a
value & doing something with it is a familiar pattern, as is matching
a whole sequence of values & doing something with the bindings. But
generating values, matching them, & then finally doing just one thing
with the bindings is, at least to me, rather strange.
An example non-intuitive use:
(match <vector>
((seq vec ((i 0 (+ i 1)))
(>= i (vector-length vec))
(vector-ref vec i)
a)
<body>))
Sorry this is a bit crude; I had to rely on the SRFI's examples.
Anyway, this is apparently allowed, although the sample implementation
raises an exception if <vector> contains more than one element. What
value should *a* be bound to in <body>? The last element of <vector>?
Syntactically, the association with 'do' is strong. Would it really
take an eccentric mind to expect <body> to be evaluated once for each
item, with a new binding of *a* on each step?
So much for the curiousities of 'seq'. 'seq*' is curiouser still, &
as for 'seq/unordered', or 'seq/reorderable', or 'seq/interleaving'
... the naming difficulties give some idea of the semantic monsters
dwelling there.
Certainly, powerful primitives for sequence patterns make sense in
an extensible system. But these aren't the primitives I'd like.
The drive for generality has made them unwieldy.
--
Wolfgang Corcoran-Mathe <xxxxxx@sigwinch.xyz>