diff --git a/assets/disk0/home/basic/autocurrytest.bas b/assets/disk0/home/basic/autocurrytest.bas new file mode 100644 index 0000000..d4206da --- /dev/null +++ b/assets/disk0/home/basic/autocurrytest.bas @@ -0,0 +1,6 @@ +10 DEFUN SINC(P)=SIN(P)/P +20 DEFUN OTHERFUN(A,B)=A+"|"+B +30 DEFUN PLOTLINE(F,X)=MAP(OTHERFUN<~F(X),1 TO 5):REM needs auto-currying +31 DEFUN PLOTLINE2(F,X)=MAP(OTHERFUN<~F<~X,1 TO 5):REM WORKS! +100 PRINT PLOTLINE(SINC,333) +101 PRINT PLOTLINE2(SINC,333) \ No newline at end of file diff --git a/assets/disk0/home/basic/sinc2.bas b/assets/disk0/home/basic/sinc2.bas index a49e95e..ae3ccf9 100644 --- a/assets/disk0/home/basic/sinc2.bas +++ b/assets/disk0/home/basic/sinc2.bas @@ -3,14 +3,7 @@ 10 DEFUN SINC(P)=IF P==0 THEN 1.0 ELSE SIN(P)/P 20 DEFUN TOCHAR(P,X)=IF (X==ROUND(ZEROLINE+P*AMP)) THEN "@" ELSE IF (X==ZEROLINE) THEN "|" ELSE CHR(250) 30 DEFUN SCONCAT(ACC,S)=ACC+S -40 REM DEFUN PLOTLINE(X)=FOLD(SCONCAT,"",MAP(TOCHAR<~X,1 TO ZEROLINE+AMP)) -41 REM PLOTLINE(F,X)=FOLD(SCONCAT,"",MAP(TOCHAR<~F(X),1 TO ZEROLINE+AMP)):REM does not work -42 DEFUN PLOTLINE(F,X)=FOLD(SCONCAT,"",MAP(TOCHAR<~F<~X,1 TO ZEROLINE+AMP)):REM WORKS! +40 DEFUN PLOTLINE(F,X)=FOLD(SCONCAT,"",MAP(TOCHAR<~F<~X,1 TO ZEROLINE+AMP)) 100 FOR I=-40 TO 40 110 PRINT PLOTLINE(SINC,I) -120 NEXT -999 END - -1000 REM Known bugs -1010 DEFUN PLOTLINE(F,X)=FOLD(SCONCAT,CHR(0),MAP(TOCHAR<~F(X),1 TO ZEROLINE+AMP)) -1011 REM calling user-defined function within DEFUN is not working \ No newline at end of file +120 NEXT \ No newline at end of file diff --git a/assets/disk0/tbas/basic.js b/assets/disk0/tbas/basic.js index 1199200..5fd551d 100644 --- a/assets/disk0/tbas/basic.js +++ b/assets/disk0/tbas/basic.js @@ -2858,6 +2858,7 @@ bF._interpretLine = function(lnum, cmd) { let syntaxTrees = bF._parseTokens(lnum, tokens, states); // syntax tree pruning + // turn UNARYMINUS(num) to -num syntaxTrees.forEach(syntaxTree => { if (syntaxTree !== undefined) { @@ -2880,6 +2881,24 @@ bF._interpretLine = function(lnum, cmd) { } }); + // automatically apply currying + // '(<~) FNQ (P X Y)' into '(<~) FNQ ((<~) P ((<~) X Y))' + // FIXME this autocurrying is very likely to be a janky-ass-shit + syntaxTrees.forEach(syntaxTree => { + if (syntaxTree !== undefined) { + bF._recurseApplyAST(syntaxTree, tree => { + if (tree.astValue == "<~" && tree.astLeaves[1] !== undefined && tree.astLeaves[1].astLeaves[0] !== undefined) { + let subTree = new BasicAST(); + subTree.astValue = "<~"; + subTree.astType = "op"; + subTree.astLnum = tree.astLnum; + subTree.astLeaves = [tree.astLeaves[1], tree.astLeaves[1].astLeaves[0]]; + + tree.astLeaves[1] = subTree; + } + }); + } + }); if (_debugprintHighestLevel) { syntaxTrees.forEach((t,i) => { serial.println("\nParsed Statement #"+(i+1));