From 6782ef3052094cfdf2345d366d42bad82e88a2b3 Mon Sep 17 00:00:00 2001 From: Joshua Maxwell <49821768+jwMaxwell@users.noreply.github.com> Date: Mon, 2 Aug 2021 15:45:25 -0500 Subject: [PATCH] Added defunc --- littlelisp.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/littlelisp.js b/littlelisp.js index bb4e163..f0a6647 100644 --- a/littlelisp.js +++ b/littlelisp.js @@ -36,6 +36,20 @@ return interpret(input[2], letContext); }, + + defunc: function(input, context) { + context.scope[input[1][0].value] = function() { + console.log('args'); + console.log(arguments); + var funcArguments = arguments; + var funcScope = input[1][1].reduce(function(acc, x, i) { + acc[x.value] = funcArguments[i]; + return acc; + }, {}); + return interpret(input[1][2], new Context(funcScope, context)); + }; + return interpret(input[2], context); + }, lambda: function(input, context) { return function() {