The evaluator already handles projection syntax via project() (imp-eval.mts:1244):
+[2; 3]works by recognizing the opener pattern"sym["- The evaluator calls
project(sym, args)which looks up the symbol and applies it - Arguments must be separated by SEP (semicolon) tokens
To work with the existing evaluator, M-expressions must be:
// Single list with verb in the opener
imp.lst({open: 'verb[', close: ']'}, [arg1, ImpC.sep(';'), arg2, ...])NOT two separate items (verb + list).
We successfully implemented transformations that work for:
2 !→2 + 3→+[2; 3](simple infix)2 + 3 * 5→*[+[2; 3]; 5](left-to-right precedence)
These pass when tested individually.
Complex interactions fail:
! 10 * 2 + 1- Mixed prefix/infix precedence- Expected:
(! 10) * 2 + 1=0 2 4 6 ... 18 - Got:
! (10 * 2 + 1)=! 21=0..20
- Expected:
1 + 2 * ! 10- Verb in right position- Error: “expected number or vector, got: JSF”
- The function isn’t being applied before the operator
- Comma threading conflicts with transformations
- The evaluator’s comma logic (lines 1100-1143) expects flat sequences
- Our transformations consume tokens before comma logic can see them
Our simple left-to-right scan can’t handle:
- Prefix verbs that need to collect arguments forward
- Checking if a verb’s arguments are complete before transforming
- Precedence changes from comma threading
The evaluator has complex logic for:
- Comma threading (lines 1100-1143)
- Infix precedence via
modifyNoun()(lines 634-686) - Prefix verb application (lines 1147-1177)
- Verb composition and modifiers
These assume flat sequences and conflict with our M-expressions.
Instead of general transformation, add a narrow fix:
- Only transform postfix unary when it’s the ONLY thing in the sequence
- Or, add special handling in the evaluator for this case
- Keep all other tests passing
Before adding more transformations:
- Move
modifyNoun()logic to imparse (infix precedence) - Move comma threading to imparse
- Move prefix application to imparse
- THEN simplify evaluator to just handle M-expressions
This requires understanding the full interaction between these pieces.
Only after evaluator is simplified:
- Enable full M-expression transformation
- All precedence/threading handled in parser
- Evaluator just evaluates M-expressions recursively
- Scan to find all verbs
- Determine their arities
- Mark which nouns are arguments to which verbs
- Handle comma boundaries
- Now that we know the structure, build the M-expressions
- Group arguments with their verbs
- Handle precedence correctly
This is more complex but handles all cases correctly.
Start with minimal fix for 2 ! bug only:
- Add special case in evaluator or very narrow transformation
- Keep all 70 tests passing
- Then incrementally move MORE logic to parser
- Each step maintains test compatibility
Don’t try to do general transformation until evaluator logic is moved.