Files
hakorune/docs/private/roadmap/phases/phase-24-ultimate-language-design/INDEX.md

237 lines
6.4 KiB
Markdown
Raw Normal View History

# Phase 24: Ultimate Language Design - Comprehensive Proposal Suite
**Generated**: 2025-10-12
**Context**: AI collaboration brainstorming session (Claude + 4 Task Agents)
**User Request**: "ultrathink task先生全員で どんな構文や機能があればいいか考えてみてー"
## 🎯 Core Philosophy
> "hakoruneは機能は最低限 糖衣構文とマクロで最強を目指していますじゃ boxでもいいよ"
**Design Principles**:
- ✅ Minimal core features (MIR 16-instruction frozen set)
- ✅ Everything desugars to Box operations
- ✅ Maximum ergonomics via sugar syntax
- ✅ Extensibility via macros and Boxes
- ✅ 80/20 rule: focus on high-impact features
---
## 📊 Proposal Summary
| Document | Count | Priority Items | Expected Impact |
|----------|-------|----------------|-----------------|
| [Sugar Syntax](sugar-syntax-proposals.md) | 22 proposals | 6 high-priority | 60-70% code reduction |
| [Macro System](macro-system-proposals.md) | 12 macros | 5 immediate-use | Testing/debugging enhancement |
| [Practical Boxes](practical-boxes-proposals.md) | 20 boxes | 5 essential | Real-world usability |
| [Language Features](language-features-analysis.md) | 20 features | 4 recommended | Ergonomics parity with modern languages |
**Total**: 74 proposals across 4 categories
---
## 🚀 Implementation Roadmap
### **Phase 1: Quick Wins** (2-3 weeks)
**Focus**: High-impact, low-complexity features
**Sugar Syntax**:
- ✅ List comprehension: `[x * 2 for x in items if x > 10]`
- ✅ String interpolation: `` `Hello, ${name}!` ``
- ✅ Null coalescing assignment: `x ??= default_value`
**Macros**:
-`@test` - test case descriptions
-`@assert` - inline assertions
**Boxes**:
- ✅ ValidationBox - input validation
- ✅ LoggerBox - structured logging
**Expected outcome**: 40-50% code reduction in common cases
---
### **Phase 2: Core Ergonomics** (3-4 weeks)
**Focus**: Language comfort features
**Sugar Syntax**:
- ✅ Null-safe operator: `person?.address?.street`
- ✅ Range operator: `0..10`, `array[2..5]`
- ✅ Arrow functions: `arr.map(x => x * 2)`
- ✅ Multiple return: `return a, b, c` → tuple
**Macros**:
-`@benchmark` - performance measurement
-`@trace` - execution tracing
-`@guard` - precondition checking
**Boxes**:
- ✅ HTTPClientBox - axios/requests equivalent
- ✅ YAMLBox - config file support
- ✅ CSVBox - data processing
**Expected outcome**: Python-level ergonomics, 60-70% code reduction
---
### **Phase 3: Advanced Features** (4-5 weeks)
**Focus**: Power user features
**Sugar Syntax**:
- ✅ Pattern matching in let: `local Ok(value) = result`
- ✅ Spread operator: `[...arr1, ...arr2]`, `{...obj1, ...obj2}`
- ✅ Pipeline operator (already implemented, enhance): `data |> transform1 |> transform2`
- ✅ Partial application: `add_10 = add(?, 10)`
**Macros**:
-`@defer` - deferred execution
-`@derive` - automatic trait implementation
-`@memo` - memoization
**Boxes**:
- ✅ TemplateEngineBox - string template rendering
- ✅ CryptoBox - encryption/hashing
- ✅ CompressionBox - gzip/zstd
**Expected outcome**: Rust-level power with better ergonomics
---
## 🎯 Priority Matrix
### **Immediate Impact** (Implement first)
1. List comprehension (60% code reduction in data processing)
2. String interpolation (eliminate ugly concatenation)
3. `@test` macro (immediate benefit for selfhost compiler testing)
4. ValidationBox (essential for real-world apps)
5. HTTPClientBox (web development essential)
### **High Value** (Implement soon)
1. Null-safe operator (crash prevention)
2. Range operator (ergonomics)
3. `@benchmark` macro (performance work)
4. LoggerBox (debugging)
5. YAMLBox (configuration)
### **Nice to Have** (Implement later)
1. Spread operator
2. Partial application
3. Advanced macros (@derive, @memo)
4. Specialized boxes (Template, Crypto, etc.)
---
## 📈 Expected Outcomes
### **Code Reduction**
```hakorune
// Before (current Hakorune)
local results
results = new ArrayBox()
local i
i = 0
loop(i < items.length()) {
local item
item = items.get(i)
if item > 10 {
results.push(item * 2)
}
i = i + 1
}
// After (with list comprehension)
local results = [item * 2 for item in items if item > 10]
```
**70% reduction**: 13 lines → 1 line
### **Ergonomics Improvement**
```hakorune
// Before (manual validation)
if name == null {
return Err("Name required")
}
if name.length() < 3 {
return Err("Name too short")
}
// After (with ValidationBox)
@validate(name, MinLength(3), Required())
```
**80% reduction**: 6 lines → 1 line
### **Testing Enhancement**
```hakorune
// Before (manual assertions)
local result
result = calculate(10, 20)
if result != 30 {
print("Test failed: expected 30, got " + result.to_string())
return 1
}
// After (with @test macro)
@test("calculate adds numbers correctly")
@assert(calculate(10, 20) == 30)
```
**90% reduction**: 6 lines → 2 lines
---
## 🔬 Design Considerations
### **Desugar to Box Operations**
All sugar syntax must compile to existing MIR 16-instruction set:
```hakorune
// List comprehension desugars to:
local results = new ArrayBox()
local __iter = items.iterator()
loop(__iter.has_next()) {
local item = __iter.next()
if item > 10 {
results.push(item * 2)
}
}
```
### **No Magic, Only Convention**
- Null-safe operator: desugar to explicit null checks
- String interpolation: desugar to StringBox operations
- Pattern matching: desugar to match expressions
- Everything follows "Everything is Box" principle
### **Backwards Compatibility**
- All new syntax is purely additive
- Existing code continues to work
- No breaking changes to MIR
- Feature flags for experimental features
---
## 📚 Related Documents
- **Sugar Syntax**: [sugar-syntax-proposals.md](sugar-syntax-proposals.md) - 22 syntax proposals
- **Macro System**: [macro-system-proposals.md](macro-system-proposals.md) - 12 macro proposals
- **Practical Boxes**: [practical-boxes-proposals.md](practical-boxes-proposals.md) - 20 Box proposals
- **Language Features**: [language-features-analysis.md](language-features-analysis.md) - 20 feature analysis
---
## 🎊 Acknowledgments
**Generated by**:
- Claude Code (orchestration)
- Task Agent 1 (sugar syntax analysis)
- Task Agent 2 (macro system design)
- Task Agent 3 (practical boxes specification)
- Task Agent 4 (language features research)
**User Philosophy**:
> "機能は最低限 糖衣構文とマクロで最強を目指していますじゃ"
This is the way. 🚀