From 88b901e86b9d7a2943f0444ae5f0a6fbbc71b1c1 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Tue, 22 Dec 2020 19:15:30 +0900 Subject: [PATCH] basic doc --- assets/tbas/doc/functions.tex | 16 ++++++++++++++++ assets/tbas/doc/langguide.tex | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/assets/tbas/doc/functions.tex b/assets/tbas/doc/functions.tex index e8b7f9b..eae8b39 100644 --- a/assets/tbas/doc/functions.tex +++ b/assets/tbas/doc/functions.tex @@ -96,10 +96,26 @@ Functions are a form of expression that may taks input arguments surrounded by p \section{Program Manipulation} \subsection{CLEAR} + \codeline{\textbf{CLEAR}}\par + Clears all declared variables. \subsection{DATA} + \codeline{\textbf{DATA} CONST0 [\textbf{,} CONST1]...}\par + Adds data that can be read by \code{READ} function. + \subsubsection*{Notes} + \begin{itemlist} + \item \code{DATA} declarations need not be reacheable in the program flow. + \end{itemlist} \subsection{END} + \codeline{\textbf{END}}\par + Stops program execution and returns control to the user. \subsection{FOR} + \codeline{\textbf{FOR} LOOPVAR \textbf{=} START \textbf{TO} STOP [\textbf{STEP} STEP]} + \codeline{\textbf{FOR} LOOPVAR \textbf{=} GENERATOR}\par + Starts a \code{FOR-NEXT} loop.\par + Initially, \code{LOOPVAR} is set to \code{START} then statements between the \code{FOR} statement and corresponding \code{NEXT} statements are executed and \code{LOOPVAR} is incremented by \code{STEP}, or by 1 if \code{STEP} is not specified. The program flow will continue to loop around until \code{LOOPVAR} is outside the range of \code{START}--\code{STOP}. The value of the \code{LOOPVAR} is equal to \code{STOP}$+$\code{STEP} when the looping finishes. \subsection{FOREACH} + \codeline{\textbf{FOREACH} LOOPVAR \textbf{IN} ARRAY}\par + Same as \code{FOR} but fetches \code{LOOPVAR} from given \code{ARRAY}. \subsection{GOSUB} \subsection{GOTO} \subsection{LABEL} diff --git a/assets/tbas/doc/langguide.tex b/assets/tbas/doc/langguide.tex index b6a2bb9..fde7f07 100644 --- a/assets/tbas/doc/langguide.tex +++ b/assets/tbas/doc/langguide.tex @@ -62,7 +62,7 @@ Using all the knowledge we have learned, it should be trivial\footnote{/s} to wr 120 PRINT QSORT(L) \end{lstlisting} -Line 12 implements quicksort algorithm, using \code{LESS} and \code{GTEQ} as helper functions. \code{LESS} is a user-function version of less-than operator, and \code{GTEQ} is similar. \code{QSORT} selects a pivot using head-element of array \code{XS}\footnote{stands for \emph{X's}} using \code{HEAD XS}, then using curried version of \code{LESS} and \code{GTEQ} to move values lesser than pivot \emph{minus the head element (here \code{TAIL XS} returns such array)} to the left and greater to the right, and these two sorted \emph{chunks} are recursively sorted using the same \code{QSORT} function. Currying is used to give comparison functions a pivot-value to compare against, and also because \code{FILTER} wants a \emph{function} and not an \emph{expression}. \code{HEAD XS} simply fetches a head-elemement of \code{XS}. \code{HEAD(XS)!NIL} creates a single-element array contains \code{XS(0)}. +Line 12 implements quicksort algorithm, using \code{LESS} and \code{GTEQ} as helper functions. \code{LESS} is a user-function version of less-than operator, and \code{GTEQ} is similar. \code{QSORT} selects a pivot by taking the head-element of the array \code{XS}\footnote{stands for \emph{X's}} with \code{HEAD(XS)}, then utilises curried version of \code{LESS} and \code{GTEQ} to move lesser-than-pivot values to the left and greater to the right (the head element itself does not get recursed, here \code{TAIL(XS)} is applied to make head-less copy of the array), and these two separated \emph{chunks} are recursively sorted using the same \code{QSORT} function. Currying is exploited to give comparison functions a pivot-value to compare against, and also because \code{FILTER} wants a \emph{function} and not an \emph{expression}. \code{HEAD(XS)!NIL} creates a single-element array contains head-element of the \code{XS}. %Uncomment this if you finally decided to support a closure% %% Using \emph{closure}, the definition of \code{QSORT} can truly be a one-liner and be \emph{even more cryptic}: