feat(core): seqable hash-maps and sets, sequential destructuring#133
Merged
Conversation
Study for replacing the U+029E-prefixed-string keyword representation with a dedicated Go type, including confirmed correctness bugs, design options and benchmarks, a migration plan targeting 0.4, and the spec for seqable hash-maps and sets. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…ring
Hash-maps seq as sorted [key value] entry vectors and sets as their
sorted elements, via a single choke point in types.GetSlice (plus
ConvertFrom for vec and a seq case for Clojure parity: seq of an empty
map or set is nil). This makes seq, first, rest, map, filter, reduce,
apply, cons, concat, vec, into and lazy-seqs work over both, enabling
(into {} (map (fn [[k v]] ...) m)).
The order is sorted rather than left unspecified because first and
rest each seq the collection independently: with Go's per-call
randomised map iteration, a first/rest traversal would drop or repeat
entries. nth rejects maps and sets explicitly (they seq but are not
indexed; Clojure errors too).
Binding forms gain sequential destructuring, which the entry idiom
requires and the language lacked: vector patterns in fn params and let
bindings bind positionally and recursively, missing elements bind nil,
& binds the remainder as a list. Top-level fn arity stays strict;
loop/recur bindings remain symbol-only.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Hash-maps and sets are now seqable, as in Clojure, and binding forms gain sequential destructuring:
[key value]entry vectors, a set as a sequence of its elements — implemented at a single choke point,types.GetSlice(plusConvertFromforvecand aseqcase).seq,first,rest,map,filter,reduce,apply,cons,concat,vec,intoand lazy-seqs work over both.keysalready does), in sorted order. Sorting is a correctness requirement, not cosmetics:firstandresteach seq the collection independently, and Go randomises map iteration per call, so an unstable order makes afirst/resttraversal (lisp-levelreduce/filter) drop or repeat entries.nthexplicitly rejects hash-maps and sets: they seq, but are not indexed collections (Clojure errors here too), and returning a sorted-order element would invite position-dependent code.fnparams andletbindings ((fn [[k v]] …),(let [[a [b c]] x] …)): positional and recursive, missing elements bindnil, extra are ignored,&binds the remainder as a list. The language previously only had&varargs, so the entry idiom above was impossible. Top-levelfnarity checking stays strict;loop/recurbindings remain symbol-only for now.Behaviour change
(seq #{})now returnsnil(Clojure parity) instead of();(seq {})is alsonil. Two step-test assertions updated accordingly.Notes
GetSlicecallers were audited (seeROADMAP-keywords.md§2, added in the first commit): the rest either gain map support with Clojure semantics or are unaffected.BenchmarkMAL1unchanged within noise.seqable_hashmap_test.gocompare multi-entry results order-insensitively.🤖 Generated with Claude Code