From b00ac13cd254b564d03018f1a11b24eba05cc0e3 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Mon, 28 Dec 2020 10:04:23 +0900 Subject: [PATCH] basic: defun f call to run on complex expr as argument, not just a constant you dumbass --- assets/disk0/home/basic/fcallcomplex.bas | 8 ++++++++ assets/disk0/tbas/basic.js | 5 ++--- 2 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 assets/disk0/home/basic/fcallcomplex.bas diff --git a/assets/disk0/home/basic/fcallcomplex.bas b/assets/disk0/home/basic/fcallcomplex.bas new file mode 100644 index 0000000..684cf65 --- /dev/null +++ b/assets/disk0/home/basic/fcallcomplex.bas @@ -0,0 +1,8 @@ +1 optiontrace 1:optiondebug 1 +10 defun fun(x)=2^x +20 defun apply(f,x)=f((x+1)/2) +30 k=apply(fun,6) +40 print k +50 print typeof k +60 unresolve k +70 resolve k diff --git a/assets/disk0/tbas/basic.js b/assets/disk0/tbas/basic.js index de5af06..7b71ae5 100644 --- a/assets/disk0/tbas/basic.js +++ b/assets/disk0/tbas/basic.js @@ -2839,9 +2839,8 @@ bF._executeSyntaxTree = function(lnum, stmtnum, syntaxTree, recDepth) { } // userdefun with args // apply given arguments (syntaxTree.astLeaves) to the expression tree and evaluate it - // if tree has leaves and their leaves are all terminal leaves (does not have grandchild AND they are not usrdefun) - else if (syntaxTree.astType == "usrdefun" && syntaxTree.astLeaves[0] !== undefined && - syntaxTree.astLeaves.every(child => child.astLeaves[0] == undefined && child.astType !== "usrdefun")) { + // if tree has leaves: + else if (syntaxTree.astType == "usrdefun" && syntaxTree.astLeaves[0] !== undefined) { let oldTree = syntaxTree.astValue; let argsTro = syntaxTree.astLeaves.map(it => bF._executeSyntaxTree(lnum, stmtnum, it, recDepth + 1)); let newTree = oldTree; // curryDefun() will make a clone of it for us