From 530bd1a2d9c6ae1b5e85c5abd50d63d8bc92fa74 Mon Sep 17 00:00:00 2001 From: Quentin Leonetti Date: Sun, 14 Jul 2019 05:56:02 +0200 Subject: [PATCH] adds def --- desktop/sources/scripts/lisp.js | 4 ++++ examples/benchmark.lisp | 7 ++++++- examples/include.lisp | 3 +++ examples/run.lisp | 1 + 4 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 examples/include.lisp create mode 100644 examples/run.lisp diff --git a/desktop/sources/scripts/lisp.js b/desktop/sources/scripts/lisp.js index 07c1eee..56eec45 100644 --- a/desktop/sources/scripts/lisp.js +++ b/desktop/sources/scripts/lisp.js @@ -34,6 +34,10 @@ function Lisp (input, lib) { return interpret(input[2], letContext) }, + def: function (input, context) { + context.scope[input[1].value] = input[2].value + return input[2] + }, lambda: function (input, context) { return function () { const lambdaArguments = arguments diff --git a/examples/benchmark.lisp b/examples/benchmark.lisp index 991fd4c..5b6abcc 100644 --- a/examples/benchmark.lisp +++ b/examples/benchmark.lisp @@ -14,7 +14,7 @@ (test "clamp" (clamp 12 4 8) 8) (test "step" (step 12 10) 10) (test "PI" TWO_PI (mul 2 PI)) - + ; Logic (test "lt" (lt 3 4) true) @@ -37,4 +37,9 @@ (test "range simple" (range 0 4) (0 1 2 3 4)) (test "range with step" (range 0 4 2) (0 2 4)) (test "range with negative step" (range 0 -4 -1) (0 -1 -2 -3 -4)) + +; Scope + + (def aaa 123) + (test "def" aaa 123) ) \ No newline at end of file diff --git a/examples/include.lisp b/examples/include.lisp new file mode 100644 index 0000000..ae2231f --- /dev/null +++ b/examples/include.lisp @@ -0,0 +1,3 @@ +( + (def value 12) +) \ No newline at end of file diff --git a/examples/run.lisp b/examples/run.lisp new file mode 100644 index 0000000..84dc6ee --- /dev/null +++ b/examples/run.lisp @@ -0,0 +1 @@ +(run "./include.lisp") \ No newline at end of file