From 6b8f64648a6807f32c0379a07178b1d4a5046dc6 Mon Sep 17 00:00:00 2001 From: cynic Date: Fri, 16 Sep 2022 12:45:46 -0400 Subject: [PATCH] cond --- .gitignore | 1 + lib.py | 16 ++++++++++++++++ test.ags => test.klambda | 9 +++++++++ 3 files changed, 26 insertions(+) create mode 100644 .gitignore rename test.ags => test.klambda (65%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ed8ebf5 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__ \ No newline at end of file diff --git a/lib.py b/lib.py index 0890675..72e67c2 100644 --- a/lib.py +++ b/lib.py @@ -25,6 +25,20 @@ def execute(ctx): return subs else: return to if i == fr else i + def _truthy(i): + if i[0] == "string": + return True if i[1] else False + elif i[0] == "number": + return False if i[1] == 0 else True + elif type(i) == type([]): + good = False + for j in i: + if _truthy(j): + good = True + break + return good + else: + return False if type(ctx) == type([]) and ctx[0][0] == "identifier": subs = list( map(lambda a: _execute(a), ctx) @@ -42,6 +56,8 @@ def execute(ctx): elif ctx[0] == _ident("defun"): funcspace[subs[1]] = subs[2] return funcspace[subs[1]] + elif ctx[0] == _ident("cond"): + return _execute(subs[2]) if _truthy(_execute(subs[1])) else _execute(subs[3]) elif ctx[0] in funcspace: prototype = funcspace[ctx[0]] for idx, arg in enumerate(subs[1:]): diff --git a/test.ags b/test.klambda similarity index 65% rename from test.ags rename to test.klambda index 0a7eef3..17d53f6 100644 --- a/test.ags +++ b/test.klambda @@ -3,6 +3,11 @@ "builtins" "print" (id $1) ) ) +(defun input + (id miracle + "builtins" "input" ("") + ) +) (defun thesis (id spit ("this language belongs to makise kurisu. there are many like it, but this one is hers.") @@ -12,4 +17,8 @@ (spit ("lol swej" (+ 9000 1) a) ) +(cond ("", (+ 0 1)) + (id spit ("one")) + (id spit ("zero")) +) (thesis) \ No newline at end of file