Summary
Add set literal documentation to PTC-Lisp specification and LLM guide, completing Phase 7 of the set literal epic (#164). This enables LLMs and developers to understand and use the new #{...} syntax.
Context
Architecture reference: Set Literal Implementation Plan - Section 5.8 (Phase 8: Documentation)
Dependencies: Phase 6 (#177) - Formatter support (completed)
Related issues: Epic #164
Current State
Based on codebase analysis:
docs/ptc-lisp-specification.md line 212 states: "Not supported: Sets (#{}), Lists ('())"
docs/ptc-lisp-llm-guide.md Data Types section lists vectors and maps but no sets
- Set literals are fully implemented (parser, analyzer, evaluator, runtime, formatter) but undocumented
Acceptance Criteria
Implementation Hints
Files to modify:
docs/ptc-lisp-specification.md - Add Section 3.8, update grammar, update type predicates, remove from "Not supported"
docs/ptc-lisp-llm-guide.md - Add sets to data types and functions reference (within PTC_PROMPT_START/PTC_PROMPT_END markers)
Content to add:
Section 3.8 Sets (for specification.md, after Section 3.7 Maps)
### 3.8 Sets
Unordered collections of unique values:
```clojure
#{} ; empty set
#{1 2 3} ; set with 3 elements
#{1 1 2} ; duplicates silently removed: equivalent to #{1 2}
#{:a :b :c} ; keyword set
Sets are unordered - iteration order is not guaranteed.
Set operations:
| Function |
Signature |
Description |
set? |
(set? x) |
Returns true if x is a set |
set |
(set coll) |
Convert collection to set |
count |
(count #{1 2}) |
Returns element count |
empty? |
(empty? #{}) |
Returns true if empty |
contains? |
(contains? #{1 2} 1) |
Membership test (O(1)) |
Collection operations on sets: map, filter, remove, mapv work on sets but return vectors (not sets).
(map inc #{1 2 3}) ; returns vector [2 3 4] (order undefined)
(filter odd? #{1 2 3 4}) ; returns vector [1 3] (order undefined)
Not supported for sets: first, last, nth, sort, sort-by (sets are unordered).
### Grammar addition (Section 14)
Add to the EBNF grammar:
1. Add new production rule:
```ebnf
set = "#{" expression* "}" ;
- Update expression alternatives to include
set:
expression = literal
| symbol
| keyword
| vector
| set
| map
| list-expr ;
Type Predicates update (Section 8.6)
Add row to the type predicates table:
LLM guide additions (within PTC_PROMPT_START markers)
Data Types section:
#{1 2 3} ; sets (unordered, unique values)
Core Functions section (add new "Sets" subsection):
; Sets
(set? x) ; is x a set?
(set [1 2 2]) ; convert to set: #{1 2}
(contains? #{1 2} 1) ; membership: true
(count #{1 2 3}) ; count: 3
(empty? #{}) ; empty check: true
Patterns to follow:
- Section 3.7 (Maps) structure for Section 3.8
- Existing function table format in Section 8.6
- Data type list format in LLM guide
Edge cases to consider:
- Ensure "Not supported" line only removes sets, keeps Lists (
'())
- Grammar section:
set must appear BEFORE map in expression alternatives (matches parser combinator ordering)
Test Plan
Manual verification:
- Grep for "Not supported" confirms sets removed
- Section numbering is correct (3.8 after 3.7)
- Grammar section includes set production and updated expression rule
Automated:
- Run
mix docs to ensure documentation compiles
- Existing tests pass (
mix test)
Out of Scope
- Adding new set operations beyond what's implemented (
union, intersection, etc.)
- Updating architecture.md (not needed for this change)
- Creating new test files (tests exist from prior phases)
Documentation Updates
docs/ptc-lisp-specification.md - Primary update
docs/ptc-lisp-llm-guide.md - Secondary update
Summary
Add set literal documentation to PTC-Lisp specification and LLM guide, completing Phase 7 of the set literal epic (#164). This enables LLMs and developers to understand and use the new
#{...}syntax.Context
Architecture reference: Set Literal Implementation Plan - Section 5.8 (Phase 8: Documentation)
Dependencies: Phase 6 (#177) - Formatter support (completed)
Related issues: Epic #164
Current State
Based on codebase analysis:
docs/ptc-lisp-specification.mdline 212 states: "Not supported: Sets (#{}), Lists ('())"docs/ptc-lisp-llm-guide.mdData Types section lists vectors and maps but no setsAcceptance Criteria
#{})" from "Not supported" line in specification (line 212)set?predicatesetto expression alternatives<!-- PTC_PROMPT_START -->markers)Implementation Hints
Files to modify:
docs/ptc-lisp-specification.md- Add Section 3.8, update grammar, update type predicates, remove from "Not supported"docs/ptc-lisp-llm-guide.md- Add sets to data types and functions reference (withinPTC_PROMPT_START/PTC_PROMPT_ENDmarkers)Content to add:
Section 3.8 Sets (for specification.md, after Section 3.7 Maps)
Sets are unordered - iteration order is not guaranteed.
Set operations:
set?(set? x)set(set coll)count(count #{1 2})empty?(empty? #{})contains?(contains? #{1 2} 1)Collection operations on sets:
map,filter,remove,mapvwork on sets but return vectors (not sets).Not supported for sets:
first,last,nth,sort,sort-by(sets are unordered).set:Type Predicates update (Section 8.6)
Add row to the type predicates table:
LLM guide additions (within PTC_PROMPT_START markers)
Data Types section:
#{1 2 3} ; sets (unordered, unique values)Core Functions section (add new "Sets" subsection):
Patterns to follow:
Edge cases to consider:
'())setmust appear BEFOREmapin expression alternatives (matches parser combinator ordering)Test Plan
Manual verification:
Automated:
mix docsto ensure documentation compilesmix test)Out of Scope
union,intersection, etc.)Documentation Updates
docs/ptc-lisp-specification.md- Primary updatedocs/ptc-lisp-llm-guide.md- Secondary update