From 83a53499bca8172ada874a19b00dcaac13796348 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Sun, 27 Dec 2020 02:56:18 +0900 Subject: [PATCH] basic: changing curry operator to (~<), i thought plunger (or grabber) is semantically less awkward than the arrow --- assets/disk0/home/basic/autocurrytest.bas | 6 ++--- assets/disk0/home/basic/curryarray.bas | 2 +- assets/disk0/home/basic/currytest.bas | 2 +- assets/disk0/home/basic/filtercurry.bas | 2 +- assets/disk0/home/basic/qsort.bas | 2 +- assets/disk0/home/basic/rallycomposition.bas | 2 +- assets/disk0/home/basic/sinc2.bas | 4 ++-- assets/disk0/tbas/basic.js | 24 +++----------------- assets/disk0/tbas/doc/langguide.tex | 8 +++---- assets/disk0/tbas/doc/tbasman.tex | 2 +- 10 files changed, 18 insertions(+), 36 deletions(-) diff --git a/assets/disk0/home/basic/autocurrytest.bas b/assets/disk0/home/basic/autocurrytest.bas index d4206da..377846f 100644 --- a/assets/disk0/home/basic/autocurrytest.bas +++ b/assets/disk0/home/basic/autocurrytest.bas @@ -1,6 +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! +30 DEFUN PLOTLINE(F,X)=MAP(OTHERFUN~=head xs] 10 DEFUN LESS(P,X)=X

=P -12 DEFUN QSORT(XS)=IF LEN(XS)<1 THEN NIL ELSE QSORT(FILTER(LESS<~HEAD(XS),TAIL(XS))) # HEAD(XS)!NIL # QSORT(FILTER(GTEQ<~HEAD(XS),TAIL(XS))) +12 DEFUN QSORT(XS)=IF LEN(XS)<1 THEN NIL ELSE QSORT(FILTER(LESS~ { // TODO test only works with DEFUN'd functions if (fn.astLeaves === undefined) throw lang.badFunctionCallFormat("Only works with DEFUN'd functions yet"); @@ -1421,12 +1421,12 @@ bF._opPrc = { "STEP":41, "!":50,"~":51, // array CONS and PUSH "#": 52, // array concat - "<~": 100, // curry operator + "~<": 100, // curry operator "~>": 101, // closure operator "=":999, "IN":1000 }; -bF._opRh = {"^":1,"=":1,"!":1,"IN":1,"~>":1}; // <~ and ~> cannot have same associativity +bF._opRh = {"^":1,"=":1,"!":1,"IN":1,"~>":1}; // ~< and ~> cannot have same associativity // these names appear on executeSyntaxTree as "exceptional terms" on parsing (regular function calls are not "exceptional terms") bF._tokenise = function(lnum, cmd) { var _debugprintStateTransition = false; @@ -2887,24 +2887,6 @@ 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)); diff --git a/assets/disk0/tbas/doc/langguide.tex b/assets/disk0/tbas/doc/langguide.tex index e993784..0fd442e 100644 --- a/assets/disk0/tbas/doc/langguide.tex +++ b/assets/disk0/tbas/doc/langguide.tex @@ -160,13 +160,13 @@ Here, \code{K} will contain the values of $1!$, $2!$ \ldots\ $10!$. Right now we \begin{lstlisting} 10 DEFUN F(K,T)=ABS(T)==K -20 CF=F<~32 +20 CF=F~<32 30 PRINT CF(24) : REM will print 'false' 40 PRINT CF(-32) : REM will print 'true' \end{lstlisting} % NOTE: you can't use \basiccurry within \code{} -Here, \code{CF} is a curried function of \code{F}; built-in operator \code{$<\!\sim$} applies \code{32} to the first parameter of the function \code{F}, which dynamically returns a \emph{function} of \code{CF(T) = ABS(T) == 32}. The fact that Curry Operator returns a \emph{function} opens many possibilities, for example, you can create loads of sibling functions without making loads of duplicate codes. +Here, \code{CF} is a curried function of \code{F}; built-in operator \code{$\sim\!<$} applies \code{32} to the first parameter of the function \code{F}, which dynamically returns a \emph{function} of \code{CF(T) = ABS(T) == 32}. The fact that Curry Operator returns a \emph{function} opens many possibilities, for example, you can create loads of sibling functions without making loads of duplicate codes. \section[Wrapping-Up]{The Grand Unification} @@ -176,8 +176,8 @@ Using all the knowledge we have learned, it should be trivial\footnote{/s} to wr 10 DEFUN LESS(P,X)=X

=P 12 DEFUN QSORT(XS)=IF LEN(XS)<1 THEN NIL ELSE - QSORT(FILTER(LESS<~HEAD(XS),TAIL(XS))) # HEAD(XS)!NIL # - QSORT(FILTER(GTEQ<~HEAD(XS),TAIL(XS))) + QSORT(FILTER(LESS~$} % Title styling