Skip to content

Commit 58de2e1

Browse files
authored
Merge pull request #7 from gram-data/006-gram-hs-migration
006 gram hs migration
2 parents 3d87610 + 4f65ff0 commit 58de2e1

File tree

27 files changed

+1111
-163
lines changed

27 files changed

+1111
-163
lines changed

.cursor/rules/specify-rules.mdc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Auto-generated from all feature plans. Last updated: 2025-12-19
99
- Haskell (GHC 9.10.3), Cabal build system + gram-hs (source repository), text, containers, megaparsec, mtl, hspec, QuickCheck (004-implementation-consistency-review)
1010
- N/A (documentation review, no data storage) (004-implementation-consistency-review)
1111
- N/A - In-memory data structures only (005-keywords-maps-sets)
12+
- Haskell (GHC 9.10.3, base >=4.18 && <5) + gram-hs library (pattern, subject, gram packages), Cabal build system (006-gram-hs-migration)
13+
- N/A (in-memory pattern structures) (006-gram-hs-migration)
1214

1315
- Haskell with GHC 9.6.3 (see research.md for version selection rationale) + gram-hs (source repository from GitHub), text, containers, megaparsec, mtl, hspec, QuickCheck (001-pattern-lisp-init)
1416

@@ -29,9 +31,9 @@ tests/
2931
Haskell with GHC 9.6.3 (see research.md for version selection rationale): Follow standard conventions
3032

3133
## Recent Changes
34+
- 006-gram-hs-migration: Added Haskell (GHC 9.10.3, base >=4.18 && <5) + gram-hs library (pattern, subject, gram packages), Cabal build system
3235
- 005-keywords-maps-sets: Added Haskell (GHC 9.10.3)
3336
- 004-implementation-consistency-review: Added Haskell (GHC 9.10.3), Cabal build system + gram-hs (source repository), text, containers, megaparsec, mtl, hspec, QuickCheck
34-
- 003-pattern-state-functions: Added Haskell with GHC 9.10.3 (as per existing project setup)
3537

3638

3739
<!-- MANUAL ADDITIONS START -->

.github/workflows/build-and-test.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ jobs:
4848
${{ runner.os }}-dist-${{ matrix.ghc-version }}-
4949
5050
- name: Configure Cabal
51-
run: cabal update
51+
run: |
52+
cabal update
5253
5354
- name: Build project
5455
run: cabal build --ghc-options="-Wall" all

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
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Specification Quality Checklist: Gram-HS Library Migration
2+
3+
**Purpose**: Validate specification completeness and quality before proceeding to planning
4+
**Created**: 2025-01-28
5+
**Feature**: [spec.md](../spec.md)
6+
7+
## Content Quality
8+
9+
- [x] No implementation details (languages, frameworks, APIs)
10+
- [x] Focused on user value and business needs
11+
- [x] Written for non-technical stakeholders
12+
- [x] All mandatory sections completed
13+
14+
## Requirement Completeness
15+
16+
- [x] No [NEEDS CLARIFICATION] markers remain
17+
- [x] Requirements are testable and unambiguous
18+
- [x] Success criteria are measurable
19+
- [x] Success criteria are technology-agnostic (no implementation details)
20+
- [x] All acceptance scenarios are defined
21+
- [x] Edge cases are identified
22+
- [x] Scope is clearly bounded
23+
- [x] Dependencies and assumptions identified
24+
25+
## Feature Readiness
26+
27+
- [x] All functional requirements have clear acceptance criteria
28+
- [x] User scenarios cover primary flows
29+
- [x] Feature meets measurable outcomes defined in Success Criteria
30+
- [x] No implementation details leak into specification
31+
32+
## Notes
33+
34+
- Migration is a technical task but has been framed from developer/user perspective
35+
- Success criteria include measurable outcomes (100% test pass rate, zero occurrences of old API)
36+
- Edge cases cover nested patterns, closures, and serialization scenarios
37+
- Scope is clearly bounded to constructor migration only
38+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Contracts: Gram-HS Constructor Migration
2+
3+
**Date**: 2025-01-28
4+
5+
## Overview
6+
7+
This migration is an internal refactoring task that updates constructor function names. No external API contracts change - this is purely an internal implementation detail.
8+
9+
## Internal API Changes
10+
11+
### Pattern Constructor Functions
12+
13+
**Before**:
14+
- `pattern :: v -> Pattern v` (atomic)
15+
- `patternWith :: v -> [Pattern v] -> Pattern v` (with elements)
16+
17+
**After**:
18+
- `point :: v -> Pattern v` (atomic)
19+
- `pattern :: v -> [Pattern v] -> Pattern v` (with elements)
20+
21+
## Impact
22+
23+
- **External API**: No changes - Pattern Lisp public API unchanged
24+
- **Internal API**: Constructor function names changed
25+
- **Serialization Format**: Unchanged - gram notation format unchanged
26+
- **Behavior**: Unchanged - only constructor names differ
27+
28+
## Migration Contract
29+
30+
All internal code using Pattern constructors must:
31+
1. Use `point` for atomic patterns
32+
2. Use `pattern` for patterns with elements
33+
3. Import `Pattern.Core (point, pattern, ...)` instead of `Pattern.Core (pattern, patternWith, ...)`
34+
35+
## Verification
36+
37+
- Type checker enforces correct usage
38+
- Test suite verifies functional correctness
39+
- No external contract changes required
40+

0 commit comments

Comments
 (0)