diff options
Diffstat (limited to 'js/scripting-lang/NEXT_STEPS.md')
-rw-r--r-- | js/scripting-lang/NEXT_STEPS.md | 236 |
1 files changed, 236 insertions, 0 deletions
diff --git a/js/scripting-lang/NEXT_STEPS.md b/js/scripting-lang/NEXT_STEPS.md new file mode 100644 index 0000000..4b21f9e --- /dev/null +++ b/js/scripting-lang/NEXT_STEPS.md @@ -0,0 +1,236 @@ +# 🎯 Next Steps: Aligning Your Baba Yaga Implementations + +## 📋 What We Just Accomplished + +✅ **Created Comprehensive Shared Test Suite** - 34 test files covering all language features +✅ **Identified Specific Discrepancies** - Detailed analysis of what differs between implementations +✅ **Proven Some Fixes Work** - Successfully fixed naming conflicts, both implementations now pass basic Turing completeness proof +✅ **Clarified Core Design Philosophy** - Single table data structure, functional combinators, immutable updates +✅ **Established Testing Framework** - You can now easily compare implementations + +## 🎯 Core Design Decisions (Agreed Upon) + +### Data Structure Philosophy +- **Single Data Structure**: Tables serve as both arrays and objects (Lua-like) +- **Functional Operations**: Use combinators (`map`, `filter`, `reduce`) rather than mutation +- **Immutable Updates**: All table operations return new tables, never modify originals + +### Table Operations Design +1. **Array-like Operations**: Use functional combinators (Option A) + ```baba-yaga + numbers : {1, 2, 3, 4, 5}; + doubled : map @double numbers; // {2, 4, 6, 8, 10} + ``` + +2. **Immutable Updates**: Explicit operations + merge (Option A + B) + ```baba-yaga + numbers : {1, 2, 3}; + with_four : t.append numbers 4; // {1, 2, 3, 4} + combined : t.merge numbers {4, 5}; // {1, 2, 3, 4, 5} + ``` + +3. **Shape Operator**: APL-inspired metadata introspection + ```baba-yaga + numbers : {1, 2, 3}; + shape : t.shape numbers; // {size: 3, type: "array"} + ``` + +4. **Error Strategy**: Fail fast on DOMAIN ERRORs + ```baba-yaga + mixed : {1, name: "Bob", 2}; + map @double mixed; // DOMAIN ERROR: Cannot apply numeric function to string + ``` + +## 🎖️ Current Implementation Status + +| Implementation | Tests Passing | Status | Next Priority | +|----------------|---------------|---------|---------------| +| **JavaScript** (Reference) | 28/34 (82%) | ✅ Strong foundation | Complete t. namespace | +| **C** | 25/34 (74%) | ⚠️ Core gaps | Fix IO & function refs | + +## 🚀 Your Immediate To-Do List + +### 1. Critical C Implementation Fixes (HIGH PRIORITY) + +**Fix A: IO Operations** (2-3 hours work) +- **Problem**: `..out` and `..assert` don't work, preventing most tests from running +- **File**: `c/src/interpreter.c` +- **Test**: `tests/unit/05_io_operations.txt` +- **Impact**: Enables basic test execution and validation + +**Fix B: Function References** (3-4 hours work) +- **Problem**: `@function` syntax not supported, blocks higher-order functions +- **Files**: `c/src/lexer.c` and `c/src/parser.c` +- **Test**: `tests/unit/08_first_class_functions.txt` +- **Impact**: Enables functional programming patterns + +**Expected Result**: C implementation jumps to ~30/34 tests passing (88%) + +### 2. Complete t. Namespace Operations (MEDIUM PRIORITY) + +**Missing Operations**: Based on failed tests and design decisions +- **t.shape**: Table introspection with metadata +- **t.append**: Immutable append operation +- **t.prepend**: Immutable prepend operation +- **t.merge**: Immutable table merging +- **DOMAIN ERROR**: Fail-fast error handling for mixed table operations + +**Implementation**: Both JavaScript and C need these operations +**Expected Result**: Both implementations reach 32+/34 tests passing (94%+) + +### 3. Rewrite Problematic Tests (1-2 hours) + +**Problem**: Some tests use invalid `[]` array syntax instead of proper table syntax +**Solution**: Convert to proper Baba Yaga table operations + +**Test Files to Fix**: +- `tests/turing-completeness/05_loops_and_state.txt` - Remove `[]` and `concat` +- `tests/turing-completeness/06_lambda_calculus.txt` - Use table operations +- `tests/turing-completeness/07_complex_algorithms.txt` - Convert to table syntax + +### 4. Use Fixed Tests Right Now (5 minutes) + +We've already created working versions of problem tests: + +```bash +# These work on BOTH implementations now: +bun js/lang.js tests/turing-completeness/01_basic_proof_compat.txt ✅ +c/bin/baba-yaga -f tests/turing-completeness/01_basic_proof_compat.txt ✅ +``` + +## 🔧 How to Validate Your Progress + +### After Each Fix: + +```bash +# Test the specific feature you fixed +./tests/run_shared_tests.sh c unit | grep "Feature Name" + +# Test full suite to see overall progress +./tests/run_shared_tests.sh c > c_results_after_fix.txt +./tests/run_shared_tests.sh js > js_results_after_fix.txt + +# Compare to see alignment +diff js_results_after_fix.txt c_results_after_fix.txt +``` + +### Target Success Metrics: +- **C Implementation**: 30+ tests passing after IO/function fixes +- **Both Implementations**: 32+ tests passing after t. namespace completion +- **Full Alignment**: Identical results on 32+ tests + +### Table Operation Validation: +```bash +# Test new t. namespace operations +bun js/lang.js -c "numbers : {1, 2, 3}; shape : t.shape numbers; ..out shape" +c/bin/baba-yaga -c "numbers : {1, 2, 3}; shape : t.shape numbers; ..out shape" + +# Test immutable updates +bun js/lang.js -c "base : {1, 2}; extended : t.append base 3; ..out extended" +``` + +## 📁 Files You'll Need to Modify + +### For C Implementation: +``` +c/src/interpreter.c - Add IO directive handling +c/src/lexer.c - Add @ token recognition +c/src/parser.c - Add function reference parsing +c/src/table.c - Add t.shape, t.append, t.prepend, t.merge operations +c/src/stdlib.c - Add DOMAIN ERROR handling +``` + +### For JavaScript Implementation: +``` +js/lang.js - Add missing t. namespace operations (t.shape, t.append, etc.) +js/parser.js - Improve error messages for invalid syntax +``` + +### For Test Files: +``` +tests/turing-completeness/05_loops_and_state.txt - Convert to table operations +tests/turing-completeness/06_lambda_calculus.txt - Remove array syntax +tests/turing-completeness/07_complex_algorithms.txt - Use proper table syntax +``` + +## 🎯 Weekly Goals + +**Week 1**: Fix critical C implementation gaps (IO operations, function references) +**Week 2**: Complete t. namespace operations in both implementations +**Week 3**: Achieve 94%+ compatibility, polish remaining edge cases + +## 💡 Key Insights from Analysis + +1. **Both implementations are fundamentally sound** - Core language works well +2. **Single table data structure is elegant** - No need for separate arrays +3. **Most failures are missing operations** - Not architectural problems +4. **JavaScript is your reference** - Use it as the source of truth for behavior +5. **Functional design is consistent** - Combinators + immutable updates align perfectly +6. **Test suite is comprehensive** - You have excellent coverage to validate fixes + +## 🏆 End Goal Vision + +When you're done, you'll have: +- ✅ Two implementations that pass 32+ of 34 tests identically +- ✅ Complete t. namespace with APL-inspired operations +- ✅ Consistent functional programming patterns across implementations +- ✅ Elegant single-table data structure working as arrays and objects +- ✅ Fail-fast DOMAIN ERROR handling for type safety +- ✅ Formal proof that Baba Yaga is Turing complete +- ✅ Professional-grade testing and development workflow + +## 📞 Recommended Workflow + +1. **Start with C fixes** - They'll give you the biggest immediate improvement +2. **Test frequently** - Run the shared test suite after each change +3. **Use compatibility tests** - We've created working versions of problematic tests +4. **Document progress** - Update the analysis files as you make changes +5. **Maintain JS as reference** - When in doubt, JS behavior is correct + +## 🚨 Warning: What NOT to Do + +❌ **Don't add array literals** - Tables are your only data structure +❌ **Don't break existing functionality** - Only add new t. namespace operations +❌ **Don't deviate from JS reference** - C implementation must match JS behavior +❌ **Don't skip testing** - Every fix needs validation with the test suite +❌ **Don't allow mutation** - All table operations must return new tables + +## 📋 Specific Implementation Details + +### t.shape Operation: +```baba-yaga +/* Array-like table */ +numbers : {1, 2, 3, 4, 5}; +shape : t.shape numbers; +// Returns: {size: 5, type: "array"} + +/* Object-like table */ +person : {name: "Alice", age: 30}; +shape : t.shape person; +// Returns: {size: 2, type: "object", keys: {"name", "age"}} + +/* Mixed table */ +mixed : {1, name: "Bob", 2}; +shape : t.shape mixed; +// Returns: {size: 3, type: "mixed", array_size: 2, object_keys: {"name"}} +``` + +### Immutable Update Operations: +```baba-yaga +base : {1, 2, 3}; +appended : t.append base 4; // {1, 2, 3, 4} +prepended : t.prepend base 0; // {0, 1, 2, 3} +merged : t.merge base {4, 5}; // {1, 2, 3, 4, 5} +``` + +### DOMAIN ERROR Handling: +```baba-yaga +mixed : {1, name: "Bob", 2}; +result : map @double mixed; // DOMAIN ERROR: Cannot apply numeric function to string key "name" +``` + +--- + +**Bottom Line**: You now have a crystal-clear roadmap based on your elegant table-centric design. Both implementations are close to full alignment - just need to complete the t. namespace operations! + +Start with the C implementation IO operations fix - it's still the highest impact change you can make. 🚀 \ No newline at end of file |