最終更新: 2025年8月12日 - Phase 1完了, P2P実装準備完了
Nyashは「Everything is Box」哲学に基づく革新的なプログラミング言語です。 Rust製インタープリターによる高性能実行と、直感的な構文により、学習しやすく実用的な言語として完成しました。
# すべてのデータがBoxとして統一的に表現される
number = 42 # IntegerBox
text = "hello" # StringBox
flag = true # BoolBox
array = new ArrayBox() # ArrayBox
debug = new DebugBox() # DebugBox
重要な利点:
// ローカル変数宣言
local x, y
local name = "Alice"
// 所有権移転変数(関数戻り値用)
outbox result = compute()
// グローバル変数
global CONFIG = "dev"
// 算術演算子
a + b, a - b, a * b, a / b
// 比較演算子
a == b, a != b, a < b, a > b, a <= b, a >= b
// 論理演算子
not condition, a and b, a or b
// Cross-type演算 (Phase 1で完全実装)
10 + 3.14 // → 13.14 (型変換)
"Value: " + 42 // → "Value: 42" (文字列連結)
box User {
init { name, email } // フィールド宣言
pack(userName, userEmail) { // 🎁 Box哲学の具現化!
me.name = userName
me.email = userEmail
}
greet() {
print("Hello, " + me.name)
}
}
box AdminUser from User { // 🔥 from構文でデリゲーション
init { permissions }
pack(adminName, adminEmail, perms) {
from User.pack(adminName, adminEmail) // 親のpack呼び出し
me.permissions = perms
}
override greet() { // 明示的オーバーライド
from User.greet() // 親メソッド呼び出し
print("Admin privileges: " + me.permissions)
}
}
static box Main {
init { console, result }
main() {
me.console = new ConsoleBox()
me.console.log("🎉 Everything is Box!")
return "Success!"
}
}
// 条件分岐
if condition {
// 処理
} else {
// 別処理
}
// ループ(唯一の正しい形式)
loop(condition) {
// 処理
if breakCondition {
break
}
}
"hello"
)42
)new FloatBox(3.14)
) ✅ Phase 1完了true
, false
)null
)new ArrayBox()
) ✅ Phase 1で sort/reverse/indexOf/slice 実装new MapBox()
)new ConsoleBox()
)new DebugBox()
)new MathBox()
)new TimeBox()
)new DateTimeBox()
) ✅ Phase 1で完全動作// 配列操作
local numbers = new ArrayBox()
numbers.push(3)
numbers.push(1)
numbers.push(2)
numbers.sort() // [1, 2, 3]
// 型変換・演算
local result = 10 + new FloatBox(3.14) // 13.14
print("Result: " + result.toString())
// P2Pノード作成
local node_a = new P2PBox("alice", transport: "inprocess")
local node_b = new P2PBox("bob", transport: "inprocess")
// メッセージ受信ハンドラ
node_b.on("chat.message", function(intent, from) {
print("From " + from + ": " + intent.payload.text)
})
// 構造化メッセージ送信
local msg = new IntentBox("chat.message", { text: "Hello P2P!" })
node_a.send("bob", msg) // → "From alice: Hello P2P!"
// ✅ 正しい
init { field1, field2 }
// ❌ 間違い(CPU暴走の原因)
init { field1 field2 }
// ✅ 明示宣言必須
local x
x = 42
// ❌ 未宣言変数への代入はエラー
y = 42 // Runtime Error + 修正提案
// ✅ 唯一の正しい形式
loop(condition) { }
// ❌ 削除済み構文
while condition { } // 使用不可
🎉 Nyashで「Everything is Box」の世界を体験しよう!
📚 関連ドキュメント: