Phase 12.7: Nyash文法革命とANCP 90%圧縮技法の発見 - 文法改革完了とFunctionBox実装

This commit is contained in:
Moe Charm
2025-09-03 20:03:45 +09:00
parent 6d79d7d3ac
commit 7455c9ec97
69 changed files with 3817 additions and 62 deletions

View File

@ -0,0 +1,5 @@
// Lambda immediate call demo
local result = (fn(a){ a + 1 })(41)
local con = new ConsoleBox()
con.println(result) // 42 を期待

View File

@ -0,0 +1,10 @@
// Capture demo:
// - locals are captured by reference using RefCellBox (use .get/.set)
// - non-locals (global/statics) are captured by value (P1)
local y = 41
local ycell = new RefCellBox(y)
local f = fn(x){ ycell.set(ycell.get() + 1); x + ycell.get() }
// outer writes through RefCellBox
// y itself remains 41; ycell holds the mutable state
local con = new ConsoleBox()
con.println(f(1)) // 43 (ycell started 41, incremented to 42, x=1 -> 43)

View File

@ -0,0 +1,8 @@
// fn{} lambda minimal (value placeholder in P1)
local f = fn(a) {
// 最後の式が返り値
a + 1
}
local con = new ConsoleBox()
// 値として持ち回れるtoStringは関数情報を表示
con.println(f.toString())

View File

@ -0,0 +1,6 @@
// Store lambda into a variable and call later
local inc = fn(a){ a + 1 }
local x = inc(41)
local con = new ConsoleBox()
con.println(x) // 42

View File

@ -0,0 +1,19 @@
// P2PBox + FunctionBox handler demo
local alice, bob, i
// create two nodes (inprocess transport)
alice = new P2PBox("alice", "inprocess")
bob = new P2PBox("bob", "inprocess")
// register a FunctionBox handler on bob
bob.on("hello", function(intent, from) {
print("[bob] received '" + intent.getName() + "' from " + from)
})
// build Intent and send from alice to bob
i = new IntentBox("hello", new MapBox())
alice.send("bob", i)
print("done")

View File

@ -1,9 +1,9 @@
// peek expression demo (P0: arms are single expressions)
// peek expression demo (P1: arms support blocks)
local animal = "cat"
local sound = peek animal {
"dog" => "bark"
"cat" => "meow"
else => "silent"
"dog" => { "bark" }
"cat" => { local s = "meow" s }
else => { "silent" }
}
local con = new ConsoleBox()
con.println(sound)

View File

@ -0,0 +1,6 @@
// ? operator demo with await (Ok path)
// await <expr> returns ResultBox Ok(expr) in this minimal path
local x = (await 42)?
local con = new ConsoleBox()
con.println(x)