From 86d0853693b271a794898bebf55aa53e24f95da9 Mon Sep 17 00:00:00 2001 From: Sander Hautvast Date: Fri, 5 Mar 2021 18:39:50 +0100 Subject: [PATCH] tweaked behavior for undefined result --- src/js/functions.js | 4 ---- src/js/index.js | 8 +++++--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/js/functions.js b/src/js/functions.js index 7f1bc04..79dee63 100644 --- a/src/js/functions.js +++ b/src/js/functions.js @@ -20,9 +20,6 @@ export const functions = { show: (args) => { return show(args[0]); }, - pi: function () { - return Math.PI; - }, sin: function (a) { return Math.sin(a); }, @@ -100,7 +97,6 @@ const create_vector = function (x0, y0, x, y) { //rename to create_vector } export const multiplication = function (left, right) { - const multiply = function (vector, scalar) { return create_vector(vector.x0 * scalar, vector.y0 * scalar, vector.x * scalar, vector.y * scalar ); diff --git a/src/js/index.js b/src/js/index.js index af67510..27b3c0d 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -25,7 +25,9 @@ let command_history_index = 0; const keywords = { 'true': true, - 'false': false + 'false': false, + 'pi': Math.PI, + 'PI': Math.PI } export const update_visible_objects = function () { @@ -238,7 +240,7 @@ const visit = function (expr) { } return value; } else { - break; + return undefined; } } } @@ -274,7 +276,7 @@ const function_call = function (function_name, argument_exprs) { if (Object.prototype.hasOwnProperty.apply(functions, [function_name])) { return functions[function_name](resolve_arguments(argument_exprs)); } else { - return `unimplemented: ${function_name}(${argument_exprs.map(e => e.value_type).join(',')})`; + return `unknown function: ${function_name}(${argument_exprs.map(e => e.value_type).join(',')})`; } }