Skip to content
This repository was archived by the owner on Apr 29, 2026. It is now read-only.

⏺ Issue #151 implementation complete. Here's a summary:#172

Merged
navicore merged 1 commit intomainfrom
a-151
Jan 4, 2026
Merged

⏺ Issue #151 implementation complete. Here's a summary:#172
navicore merged 1 commit intomainfrom
a-151

Conversation

@navicore
Copy link
Copy Markdown
Owner

@navicore navicore commented Jan 4, 2026

Implementation Summary

#151

Challenge: The original kv-map ( k1 v1 ... kN vN n -- Map ) design can't work with Seq's type system - it can't express consuming a variable number of stack items based on a runtime value.

Solution: Builder pattern with two simple words:

include std:map

Build a map with chained operations

map-of "name" "Alice" kv "age" 30 kv

Multi-line style

map-of
"host" "localhost" kv
"port" 8080 kv
"debug" true kv

Files created/modified:

  • crates/compiler/stdlib/map.seq - new stdlib module with map-of and kv
  • crates/compiler/src/stdlib_embed.rs - registered the map module
  • tests/integration/src/test-kv-map.seq - 6 passing tests

CI status: All 233 compiler tests + 291 runtime tests + 6 new tests pass.

  Implementation Summary

  Challenge: The original kv-map ( k1 v1 ... kN vN n -- Map ) design can't work with Seq's type system - it can't express consuming a variable number of stack items based on a runtime value.

  Solution: Builder pattern with two simple words:

  include std:map

  # Build a map with chained operations
  map-of "name" "Alice" kv "age" 30 kv

  # Multi-line style
  map-of
    "host" "localhost" kv
    "port" 8080 kv
    "debug" true kv

  Files created/modified:
  - crates/compiler/stdlib/map.seq - new stdlib module with map-of and kv
  - crates/compiler/src/stdlib_embed.rs - registered the map module
  - tests/integration/src/test-kv-map.seq - 6 passing tests

  CI status: All 233 compiler tests + 291 runtime tests + 6 new tests pass.
@navicore navicore mentioned this pull request Jan 4, 2026
@claude
Copy link
Copy Markdown

claude Bot commented Jan 4, 2026

PR Review: Map Builder Pattern Implementation

Overall Assessment

Status: APPROVED

This PR successfully implements a clean builder pattern for map construction that elegantly solves the type system limitations described in issue #151. The implementation is well-designed, thoroughly tested, and follows existing stdlib conventions.


Code Quality & Best Practices

Strengths ✅

  1. Excellent Design Decision: The builder pattern (map-of ... kv ... kv) is the right solution given Seq's type system constraints. Unlike the count-based approach from the issue, this doesn't require consuming a variable number of stack items based on runtime values.

  2. Consistent with Stdlib Conventions:

    • Documentation style matches result.seq and stack-utils.seq
    • Clear usage examples with multiple styles shown
    • Proper stack effect comments
    • Good use of aliases for clarity
  3. Clean Implementation: Both map-of and kv are simple, readable aliases that leverage existing primitives. No unnecessary complexity.

  4. Integration: Properly registered in stdlib_embed.rs following the existing pattern.


Test Coverage

Strengths ✅

The test suite in test-kv-map.seq is comprehensive with 6 well-designed test cases:

  1. test-map-builder-basic: Tests 2 key-value pairs
  2. test-map-builder-single: Tests single pair
  3. test-map-builder-empty: Tests empty map creation
  4. test-map-builder-int-keys: Tests integer keys (type flexibility)
  5. test-map-builder-chained: Tests multi-line chaining pattern
  6. test-map-builder-duplicate-keys: Tests overwrite behavior

Coverage Analysis:

  • Edge cases: empty maps ✅
  • Different key types: strings, integers ✅
  • Duplicate keys: verified overwrite behavior ✅
  • Chaining pattern: demonstrated multi-line usage ✅

Potential Issues & Suggestions

Minor Documentation Enhancement 💡

Current code (crates/compiler/stdlib/map.seq:22-24):

: map-of ( -- Map )
  map.make
;

Suggestion: Consider adding a comment about the builder pattern's type safety advantage:

# Create an empty map (alias for map.make)
# Unlike count-based approaches, this builder pattern is type-safe
# because each kv call is a separate stack operation
: map-of ( -- Map )
  map.make
;

This helps explain why this approach was chosen over the alternatives in issue #151.

Test Case: Consider Boolean Keys 💡

The existing tests cover string and integer keys. For completeness, you might add a test with boolean keys (similar to test-bool-keys in test-map-ops.seq:83-90), though this is optional since the type flexibility is already demonstrated.


Performance Considerations

No concerns. The implementation:

  • Uses simple aliases with no overhead
  • Delegates to existing map.make and map.set primitives
  • Builder pattern has same performance as manual map.set calls
  • No unnecessary allocations or computations

Security Concerns

No concerns. The code:

  • Contains no unsafe operations
  • No input validation needed (type system handles this)
  • No resource management issues
  • Pure stack manipulation with well-defined semantics

Bugs or Issues

None identified. The implementation is correct and handles edge cases properly:

  • Empty maps work correctly
  • Duplicate keys are handled by map.set (overwrites as expected)
  • Type flexibility is preserved from underlying map operations

Final Recommendation

APPROVE - This PR is ready to merge.

The implementation is:

  • ✅ Correct and well-tested
  • ✅ Follows project conventions
  • ✅ Solves the stated problem elegantly
  • ✅ Has excellent test coverage
  • ✅ Well-documented with clear examples

The builder pattern is a smart solution that works within Seq's type system constraints while providing the ergonomic map construction syntax needed for SON.

CI Status: All 233 compiler tests + 291 runtime tests + 6 new tests passing ✅

@navicore navicore merged commit 12d02e3 into main Jan 4, 2026
2 checks passed
@navicore navicore deleted the a-151 branch January 4, 2026 01:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant