From 349bae7c5d90f0a3cae2477f0b7f2fb2c7226d67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=B6=E5=A1=9A=E5=A4=AA=E6=99=BA?= Date: Sun, 12 Jan 2025 14:06:22 +0900 Subject: [PATCH] Update selfhost.lm --- example/langs/selfhost.lm | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/example/langs/selfhost.lm b/example/langs/selfhost.lm index 0c7058d..57e14cd 100644 --- a/example/langs/selfhost.lm +++ b/example/langs/selfhost.lm @@ -7,9 +7,10 @@ let evalExpr = fn(e, x -> [scope, scope[ast.value]] }, #Apply => { - let [[scope, a], [scope, b]] = map (evalExpr scope) ast.value; - let [funcScope, expr] = [scope, betaReduct a.value[0] b a.value[1]]; - evalExpr funcScope expr + let [[scope, func], [scope, value]] = map (evalExpr scope) ast.value; + let [[arg, body], funcScope] = [func.value, scope]; + let body = betaReduct(arg, value, body); + evalExpr funcScope body }, #Add => { let [[scope, a], [scope, b]] = map (evalExpr scope) ast.value; @@ -79,6 +80,10 @@ let parseExpr = fn(source -> let token = token - "λ" / "."; let [args, body] = [token[0], join token[1 ~ len(token)] "."]; @{ "class": #Lambda, "value": [args, (parseExpr body)] } + } else if (token[0] == "\\" & token["."]) { + let token = token - "\\" / "."; + let [args, body] = [token[0], join token[1 ~ len(token)] "."]; + @{ "class": #Lambda, "value": [args, (parseExpr body)] } } else { @{ "class": #Symbol, "value": token } }