Skip to content

Commit 6c3eccb

Browse files
committed
gram-hs-migrate: updated use of gram-hs; reflected api changes in plisp, which now uses pattern and pure
1 parent 12f5167 commit 6c3eccb

File tree

18 files changed

+200
-199
lines changed

18 files changed

+200
-199
lines changed

docs/pattern-state-lisp-design.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Where:
3838
```scheme
3939
;; Pure function, runtime handles state threading
4040
(lambda (state)
41-
(pattern-with
41+
(pattern
4242
(pattern-value state)
4343
(cons new-item (pattern-elements state))))
4444
```
@@ -54,7 +54,7 @@ Tools in Pattern Agents are naturally `Pattern v -> Pattern v` transformations:
5454
(lambda (state)
5555
(let* ((user (pattern-find state is-user?))
5656
(name (pattern-query user "$.name")))
57-
(pattern-with
57+
(pattern
5858
{:greeting (string-append "Hello, " name)}
5959
(pattern-elements state))))
6060
```
@@ -72,7 +72,7 @@ Tools compose as functions:
7272
(define format-greeting
7373
(lambda (state)
7474
(let ((user (get-user state)))
75-
(pattern {:greeting (string-append "Hello, " (pattern-value user))}))))
75+
(pure {:greeting (string-append "Hello, " (pattern-value user))}))))
7676
7777
;; Compose: format-greeting ∘ get-user
7878
(define greet-user
@@ -177,8 +177,8 @@ Pattern is a **native Lisp value type**, not accessed through host-calls.
177177

178178
```scheme
179179
;; Pattern construction
180-
(pattern value) ; Atomic pattern
181-
(pattern-with value elements) ; Pattern with elements
180+
(pure value) ; Atomic pattern
181+
(pattern value elements) ; Pattern with elements
182182
(from-list value [v1 v2 v3]) ; Convenience constructor
183183
184184
;; Pattern transformation (returns new pattern)
@@ -220,7 +220,7 @@ Since programs are pure, **host-calls** are the only mechanism for side effects:
220220
"SELECT * FROM users WHERE id = ?"
221221
user-id)))
222222
;; Incorporate result into new state pattern
223-
(pattern-with
223+
(pattern
224224
{:query-result db-result}
225225
(pattern-elements state)))))
226226
```
@@ -316,12 +316,12 @@ executeTool toolName runtime = do
316316
(db-result (host-call 'db-query
317317
"SELECT * FROM orders WHERE id = ?"
318318
order-id))
319-
(order-pattern (pattern-with
319+
(order-pattern (pattern
320320
{:type "Order"
321321
:id order-id
322322
:data db-result}
323323
[])))
324-
(pattern-with
324+
(pattern
325325
(pattern-value state)
326326
(cons order-pattern (pattern-elements state)))))
327327
]
@@ -337,14 +337,14 @@ executeTool toolName runtime = do
337337
(db-result (host-call 'db-query
338338
"SELECT * FROM orders WHERE id = ?"
339339
order-id))
340-
(order-pattern (pattern-with
341-
{:type "Order"
342-
:id order-id
343-
:data db-result}
344-
[])))
345-
(pattern-with
346-
(pattern-value state)
347-
(cons order-pattern (pattern-elements state)))))
340+
(order-pattern (pattern
341+
{:type "Order"
342+
:id order-id
343+
:data db-result}
344+
[])))
345+
(pattern
346+
(pattern-value state)
347+
(cons order-pattern (pattern-elements state)))))
348348
```
349349

350350
## Benefits for Pattern Agents

docs/plisp-serialization-design.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ Every Pattern Lisp runtime provides a standard environment (`initialEnv`) contai
606606
- Arithmetic primitives: `+`, `-`, `*`, `/`
607607
- Comparison primitives: `>`, `<`, `=`, `/=`
608608
- String primitives: `string-append`, `string-length`, `substring`
609-
- Pattern primitives: `pattern`, `pattern-with`, `pattern-value`, etc.
609+
- Pattern primitives: `pure`, `pattern`, `pattern-value`, etc.
610610

611611
### Environment Filtering
612612

@@ -1245,10 +1245,10 @@ Pattern Subject → Check Label:
12451245
**S-expression**:
12461246
```scheme
12471247
(lambda (state)
1248-
(pattern-with
1248+
(pattern
12491249
(pattern-value state)
12501250
(cons
1251-
(pattern "new-item")
1251+
(pure "new-item")
12521252
(pattern-elements state))))
12531253
```
12541254

@@ -1262,7 +1262,7 @@ Pattern Subject → Check Label:
12621262
[:Parameters | state],
12631263
[:Body |
12641264
[:List |
1265-
[:Symbol {name: "pattern-with"}],
1265+
[:Symbol {name: "pattern"}],
12661266
[:List | [:Symbol {name: "pattern-value"}], state],
12671267
[:List |
12681268
[:Symbol {name: "cons"}],

examples/pattern-basics.plisp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
;; Demonstrates creating and querying Pattern values
33

44
;; Create an atomic pattern
5-
(define hello (pattern "hello"))
5+
(define hello (pure "hello"))
66

77
;; Create a pattern with elements (empty for now)
8-
(define root (pattern-with "root" '()))
8+
(define root (pattern "root" '()))
99

1010
;; Query pattern decoration
1111
(pattern-value hello)

examples/pattern-predicates.plisp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
;; ============================================================================
1010

1111
;; Create some atomic patterns for testing
12-
(define p1 (pattern 10))
13-
(define p2 (pattern 20))
14-
(define p3 (pattern 30))
12+
(define p1 (pure 10))
13+
(define p2 (pure 20))
14+
(define p3 (pure 30))
1515

1616
;; pattern-find: Find the first matching subpattern
1717
;; Returns the matching pattern, or empty list if no match

specs/003-pattern-state-functions/quickstart.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ cabal build all
3535

3636
```scheme
3737
;; Create an atomic pattern
38-
(define atomic (pattern "hello"))
38+
(define atomic (pure "hello"))
3939
4040
;; Create a pattern with elements
41-
(define with-elements (pattern-with "root"
42-
(list (pattern "child1") (pattern "child2"))))
41+
(define with-elements (pattern "root"
42+
(list (pure "child1") (pure "child2"))))
4343
```
4444

4545
### 2. Querying Pattern Values
@@ -64,10 +64,10 @@ All tools must follow the canonical form `(lambda (state) ...)`:
6464
```scheme
6565
;; Simple tool that adds a greeting
6666
(lambda (state)
67-
(pattern-with
67+
(pattern
6868
(pattern-value state) ; Preserve decoration
6969
(cons
70-
(pattern "Hello from Pattern Lisp!")
70+
(pure "Hello from Pattern Lisp!")
7171
(pattern-elements state))))
7272
```
7373

@@ -173,13 +173,13 @@ Deserializes runtime from a Gram file and resumes execution.
173173
(lambda (state)
174174
(let ((count (pattern-size state))
175175
(depth (pattern-depth state)))
176-
(pattern-with
176+
(pattern
177177
(pattern-value state)
178-
(cons
179-
(pattern-with "summary"
180-
(list
181-
(pattern count)
182-
(pattern depth)))
178+
(cons
179+
(pattern "summary"
180+
(list
181+
(pure count)
182+
(pure depth)))
183183
(pattern-elements state)))))
184184
185185
;; 2. Save to file: state-reader.plisp
@@ -269,13 +269,13 @@ it "round-trips closures" $ do
269269
;; Define multiple tools
270270
(define add-timestamp
271271
(lambda (state)
272-
(pattern-with (pattern-value state)
273-
(cons (pattern "timestamp") (pattern-elements state)))))
272+
(pattern (pattern-value state)
273+
(cons (pure "timestamp") (pattern-elements state)))))
274274
275275
(define add-metadata
276276
(lambda (state)
277-
(pattern-with (pattern-value state)
278-
(cons (pattern "metadata") (pattern-elements state)))))
277+
(pattern (pattern-value state)
278+
(cons (pure "metadata") (pattern-elements state)))))
279279
280280
;; Compose tools
281281
(lambda (state)
@@ -289,9 +289,9 @@ it "round-trips closures" $ do
289289
(lambda (state)
290290
(let ((incrementer (lambda (x) (+ x 1)))
291291
(doubler (lambda (x) (* x 2))))
292-
(pattern-with "functions"
293-
(list (pattern incrementer)
294-
(pattern doubler)))))
292+
(pattern "functions"
293+
(list (pure incrementer)
294+
(pure doubler)))))
295295
```
296296

297297
### State Filtering
@@ -302,7 +302,7 @@ it "round-trips closures" $ do
302302
(let ((filtered (pattern-find state
303303
(lambda (p)
304304
(> (pattern-size p) 1)))))
305-
(pattern-with "filtered" (list filtered))))
305+
(pattern "filtered" (list filtered))))
306306
```
307307

308308
## Troubleshooting

specs/006-gram-hs-migration/tasks.md

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424

2525
**Purpose**: Verify prerequisites and understand migration requirements
2626

27-
- [ ] T001 Verify updated gram-hs library is available and compatible with current GHC version
28-
- [ ] T002 Read migration guide at `../gram-hs/docs/users/migration/rename-constructors.md` and understand breaking changes
29-
- [ ] T003 Verify existing test suite passes before migration: `cabal test`
27+
- [x] T001 Verify updated gram-hs library is available and compatible with current GHC version
28+
- [x] T002 Read migration guide at `../gram-hs/docs/users/migration/rename-constructors.md` and understand breaking changes
29+
- [x] T003 Verify existing test suite passes before migration: `cabal test`
3030

3131
**Checkpoint**: Prerequisites verified - ready to begin migration
3232

@@ -40,15 +40,15 @@
4040

4141
### Implementation for User Story 1
4242

43-
- [ ] T004 [P] [US1] Update import in `src/PatternLisp/Codec.hs`: Change `import Pattern.Core (pattern, patternWith)` to `import Pattern.Core (point, pattern)`
44-
- [ ] T005 [P] [US1] Update import in `src/PatternLisp/PatternPrimitives.hs`: Change `import Pattern.Core (pattern, patternWith)` to `import Pattern.Core (point, pattern)`
45-
- [ ] T006 [P] [US1] Update import in `src/PatternLisp/Gram.hs`: Change `import Pattern.Core (pattern)` to `import Pattern.Core (point, pattern)`
46-
- [ ] T007 [P] [US1] Update import in `test/PatternLisp/CodecSpec.hs`: Change `import Pattern.Core (pattern, patternWith)` to `import Pattern.Core (point, pattern)`
47-
- [ ] T008 [P] [US1] Update import in `test/PatternLisp/GramSpec.hs`: Change `import Pattern.Core (pattern, patternWith)` to `import Pattern.Core (point, pattern)`
48-
- [ ] T009 [P] [US1] Update import in `test/PatternLisp/GramSerializationSpec.hs`: Change `import Pattern.Core (pattern, patternWith)` to `import Pattern.Core (point, pattern)`
49-
- [ ] T010 [P] [US1] Update import in `test/PatternLisp/RuntimeSpec.hs`: Change `import Pattern.Core (pattern)` to `import Pattern.Core (point, pattern)`
50-
- [ ] T011 [US1] Verify all imports updated: Run `grep -r "patternWith" src/ test/ | grep -i import` to confirm no old imports remain
51-
- [ ] T012 [US1] Verify compilation: Run `cabal build` to ensure no import-related errors
43+
- [x] T004 [P] [US1] Update import in `src/PatternLisp/Codec.hs`: Change `import Pattern.Core (pattern, patternWith)` to `import Pattern.Core (point, pattern)`
44+
- [x] T005 [P] [US1] Update import in `src/PatternLisp/PatternPrimitives.hs`: Change `import Pattern.Core (pattern, patternWith)` to `import Pattern.Core (point, pattern)`
45+
- [x] T006 [P] [US1] Update import in `src/PatternLisp/Gram.hs`: Change `import Pattern.Core (pattern)` to `import Pattern.Core (point, pattern)`
46+
- [x] T007 [P] [US1] Update import in `test/PatternLisp/CodecSpec.hs`: Change `import Pattern.Core (pattern, patternWith)` to `import Pattern.Core (point, pattern)`
47+
- [x] T008 [P] [US1] Update import in `test/PatternLisp/GramSpec.hs`: Change `import Pattern.Core (pattern, patternWith)` to `import Pattern.Core (point, pattern)`
48+
- [x] T009 [P] [US1] Update import in `test/PatternLisp/GramSerializationSpec.hs`: Change `import Pattern.Core (pattern, patternWith)` to `import Pattern.Core (point, pattern)`
49+
- [x] T010 [P] [US1] Update import in `test/PatternLisp/RuntimeSpec.hs`: Change `import Pattern.Core (pattern)` to `import Pattern.Core (point, pattern)`
50+
- [x] T011 [US1] Verify all imports updated: Run `grep -r "patternWith" src/ test/ | grep -i import` to confirm no old imports remain
51+
- [x] T012 [US1] Verify compilation: Run `cabal build` to ensure no import-related errors
5252

5353
**Checkpoint**: All imports updated - code should compile (may have errors from old constructor usage, which is expected)
5454

@@ -62,12 +62,12 @@
6262

6363
### Implementation for User Story 2
6464

65-
- [ ] T013 [P] [US2] Replace atomic `pattern` calls in `src/PatternLisp/Codec.hs`: Find all `pattern $` and `pattern subject` (single argument) and replace with `point $` and `point subject`
66-
- [ ] T014 [P] [US2] Replace atomic `pattern` calls in `src/PatternLisp/PatternPrimitives.hs`: Find all `pattern subject` (single argument) and replace with `point subject`
67-
- [ ] T015 [P] [US2] Replace atomic `pattern` calls in `src/PatternLisp/Gram.hs`: Replace `pattern subject` with `point subject` in `exprToGram` function
68-
- [ ] T016 [P] [US2] Replace atomic `pattern` calls in `test/PatternLisp/RuntimeSpec.hs`: Replace any atomic `pattern` calls with `point`
69-
- [ ] T017 [US2] Verify atomic patterns migrated: Run `grep -r "pattern \$" src/ test/` and `grep -r "pattern [^W]" src/ test/` to check for remaining atomic patterns (excluding `patternWith`)
70-
- [ ] T018 [US2] Verify compilation: Run `cabal build` to ensure atomic pattern replacements are correct
65+
- [x] T013 [P] [US2] Replace atomic `pattern` calls in `src/PatternLisp/Codec.hs`: Find all `pattern $` and `pattern subject` (single argument) and replace with `point $` and `point subject`
66+
- [x] T014 [P] [US2] Replace atomic `pattern` calls in `src/PatternLisp/PatternPrimitives.hs`: Find all `pattern subject` (single argument) and replace with `point subject`
67+
- [x] T015 [P] [US2] Replace atomic `pattern` calls in `src/PatternLisp/Gram.hs`: Replace `pattern subject` with `point subject` in `exprToGram` function
68+
- [x] T016 [P] [US2] Replace atomic `pattern` calls in `test/PatternLisp/RuntimeSpec.hs`: Replace any atomic `pattern` calls with `point`
69+
- [x] T017 [US2] Verify atomic patterns migrated: Run `grep -r "pattern \$" src/ test/` and `grep -r "pattern [^W]" src/ test/` to check for remaining atomic patterns (excluding `patternWith`)
70+
- [x] T018 [US2] Verify compilation: Run `cabal build` to ensure atomic pattern replacements are correct
7171

7272
**Checkpoint**: All atomic patterns use `point` - compilation should succeed for atomic patterns
7373

@@ -81,13 +81,13 @@
8181

8282
### Implementation for User Story 3
8383

84-
- [ ] T019 [P] [US3] Replace `patternWith` calls in `src/PatternLisp/Codec.hs`: Replace all ~30+ occurrences of `patternWith` with `pattern`
85-
- [ ] T020 [P] [US3] Replace `patternWith` calls in `src/PatternLisp/PatternPrimitives.hs`: Replace all 4 occurrences of `patternWith` with `pattern`
86-
- [ ] T021 [P] [US3] Replace `patternWith` calls in `test/PatternLisp/GramSpec.hs`: Replace `patternWith` with `pattern`
87-
- [ ] T022 [P] [US3] Replace `patternWith` calls in `test/PatternLisp/GramSerializationSpec.hs`: Replace `patternWith` with `pattern`
88-
- [ ] T023 [US3] Verify all `patternWith` replaced: Run `grep -r "patternWith" src/ test/` to confirm no function calls remain (comments may still reference)
89-
- [ ] T024 [US3] Verify compilation: Run `cabal build` to ensure all `patternWith` replacements are correct
90-
- [ ] T025 [US3] Verify nested patterns: Check that nested patterns correctly use `point` for atomic children and `pattern` for non-atomic children
84+
- [x] T019 [P] [US3] Replace `patternWith` calls in `src/PatternLisp/Codec.hs`: Replace all ~30+ occurrences of `patternWith` with `pattern`
85+
- [x] T020 [P] [US3] Replace `patternWith` calls in `src/PatternLisp/PatternPrimitives.hs`: Replace all 4 occurrences of `patternWith` with `pattern`
86+
- [x] T021 [P] [US3] Replace `patternWith` calls in `test/PatternLisp/GramSpec.hs`: Replace `patternWith` with `pattern`
87+
- [x] T022 [P] [US3] Replace `patternWith` calls in `test/PatternLisp/GramSerializationSpec.hs`: Replace `patternWith` with `pattern`
88+
- [x] T023 [US3] Verify all `patternWith` replaced: Run `grep -r "patternWith" src/ test/` to confirm no function calls remain (comments may still reference)
89+
- [x] T024 [US3] Verify compilation: Run `cabal build` to ensure all `patternWith` replacements are correct
90+
- [x] T025 [US3] Verify nested patterns: Check that nested patterns correctly use `point` for atomic children and `pattern` for non-atomic children
9191

9292
**Checkpoint**: All `patternWith` calls replaced with `pattern` - full migration of constructor calls complete
9393

@@ -101,12 +101,12 @@
101101

102102
### Implementation for User Story 4
103103

104-
- [ ] T026 [US4] Search for remaining `patternWith` function calls: Run `grep -r "patternWith" src/ test/` and verify only comments/documentation references remain
105-
- [ ] T027 [US4] Search for incorrect atomic `pattern` usage: Run `grep -r "pattern \$" src/ test/` and verify all are intentional (not atomic patterns that should be `point`)
106-
- [ ] T028 [US4] Verify compilation: Run `cabal build` and ensure zero errors related to Pattern constructors
107-
- [ ] T029 [US4] Run full test suite: Execute `cabal test` and verify 100% test pass rate
108-
- [ ] T030 [US4] Test example programs: Run example programs through interpreter and verify they produce same results as before migration
109-
- [ ] T031 [US4] Verify serialization round-trips: Test pattern serialization/deserialization for all pattern types (atomic, lists, maps, sets, closures, nested)
104+
- [x] T026 [US4] Search for remaining `patternWith` function calls: Run `grep -r "patternWith" src/ test/` and verify only comments/documentation references remain
105+
- [x] T027 [US4] Search for incorrect atomic `pattern` usage: Run `grep -r "pattern \$" src/ test/` and verify all are intentional (not atomic patterns that should be `point`)
106+
- [x] T028 [US4] Verify compilation: Run `cabal build` and ensure zero errors related to Pattern constructors
107+
- [x] T029 [US4] Run full test suite: Execute `cabal test` and verify 100% test pass rate
108+
- [x] T030 [US4] Test example programs: Run example programs through interpreter and verify they produce same results as before migration
109+
- [x] T031 [US4] Verify serialization round-trips: Test pattern serialization/deserialization for all pattern types (atomic, lists, maps, sets, closures, nested)
110110

111111
**Checkpoint**: Migration verified complete - all tests pass, no old API usage remains
112112

@@ -116,13 +116,13 @@
116116

117117
**Purpose**: Update code comments and documentation examples to reflect new API
118118

119-
- [ ] T032 [P] Update Haddock examples in `src/PatternLisp/PatternPrimitives.hs`: Replace `evalPatternWith` example comments to use new API if they reference constructors
120-
- [ ] T033 [P] Update inline comments in `src/PatternLisp/Codec.hs`: Review and update any comments that reference old constructor names
121-
- [ ] T034 [P] Update module documentation examples: Review module headers for example code snippets referencing old API
122-
- [ ] T035 [P] Update comments in `test/PatternLisp/` files: Review test file comments for old API references
123-
- [ ] T036 Verify comment updates: Run final `grep -r "patternWith" src/ test/` to confirm only historical references remain (if any)
124-
- [ ] T037 Final compilation check: Run `cabal build` one final time
125-
- [ ] T038 Final test check: Run `cabal test` one final time to ensure everything still works
119+
- [x] T032 [P] Update Haddock examples in `src/PatternLisp/PatternPrimitives.hs`: Replace `evalPatternWith` example comments to use new API if they reference constructors
120+
- [x] T033 [P] Update inline comments in `src/PatternLisp/Codec.hs`: Review and update any comments that reference old constructor names
121+
- [x] T034 [P] Update module documentation examples: Review module headers for example code snippets referencing old API
122+
- [x] T035 [P] Update comments in `test/PatternLisp/` files: Review test file comments for old API references
123+
- [x] T036 Verify comment updates: Run final `grep -r "patternWith" src/ test/` to confirm only historical references remain (if any)
124+
- [x] T037 Final compilation check: Run `cabal build` one final time
125+
- [x] T038 Final test check: Run `cabal test` one final time to ensure everything still works
126126

127127
**Checkpoint**: Migration complete - code, tests, and documentation all updated
128128

0 commit comments

Comments
 (0)