Map builder word for SON #151
Labels
No labels
bug
dependencies
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
refactor
rust
technical-debt
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
navicore/patch-seq#151
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
SON (Seq Object Notation) needs a concise way to build maps from key-value pairs:
Currently building a map requires:
Proposed Words
Option A: Count-based
Option B: Sentinel-based
Option C: Quotation-based
Implementation Notes
map.setExample Usage in SON
Relation to SON
This is a quality-of-life feature. Without it, SON map literals are verbose:
Part of the SON implementation roadmap.
Difficulty: Low
Dependencies: None (can use existing map.make/map.set)
Implementation Update
I've implemented a builder pattern approach instead of the count-based
kv-mapproposed in Option A. Here's why:The Type System Challenge
Seq's type checker can't express variable-arity stack effects. The proposed:
Would require a type signature like
( k1 v1 ... kN vN Int -- Map )which can't be expressed - the type checker sees( Int -- Map )and doesn't know about the pairs.Solution: Builder Pattern
The new
std:mapstdlib provides:Words provided:
map-of- creates empty map (alias formap.make)kv- adds key-value pair (alias formap.set)Comparison with Original SON Examples
Original goal:
Builder pattern:
The builder approach is slightly more verbose but:
Files Added/Modified
crates/compiler/stdlib/map.seq- new stdlib modulecrates/compiler/src/stdlib_embed.rs- added map to embedded stdlibtests/integration/src/test-kv-map.seq- tests for builder patternAll 6 tests pass, CI green. Ready for review!
https://github.com/navicore/patch-seq/pull/172