diff --git a/assets/tbas/doc/concepts.tex b/assets/tbas/doc/concepts.tex index 7d5f6bc..9897416 100644 --- a/assets/tbas/doc/concepts.tex +++ b/assets/tbas/doc/concepts.tex @@ -1,4 +1,7 @@ -This chapter describes the basic concepts of the language. +\quad +\chapterprecishere{``Caution! Under no circumstances confuse the adjective \emph{basic} with the noun \emph{BASIC}, except under confusing circumstances!''\par\raggedleft --- \textup{\tbas{} Reference Manual, \theedition}\footnote{Original quotation is from \emph{The INTERCAL Programming Language Reference Manual} by Donald R. Woods and James M. Lyon}} + +This chapter describes the basic concepts of the \tbas{} language. \section{Values and Types} @@ -18,4 +21,18 @@ There are six basic types: \emph{number}, \emph{boolean}, \emph{string}, \emph{ \emph{Generator} represents a value that automatically counts up/down whenever they have been called in For-Next loop. -\emph{Functions} are, well\ldots functions\footnote{This is no {\lambda}-expression; there is no way you can define local- or anonymous variable in BASIC.}, especially user-defined ones. Functions are \emph{type} because some built-in functions will actually take \emph{functions} as arguments. +\emph{Functions} are, well\ldots functions\footnote{This is not a closure; there is no way you can define a local- or anonymous variable in BASIC.}, especially user-defined ones. Functions are \emph{type} because some built-in functions will actually take \emph{functions} as arguments. + +\section{Control Flow} + +A program is executed starting with its lowest line number. Statements on a line are executed from left to right. When all Statements are finished execution, next lowest line number will be executed. Control flow functions can modify this normal flow. + +You can dive into other line in the middle of the program with \code{GOTO}. The program flow will continue normally at the new line \emph{and it will never know ya just did that}. + +If you want less insane jumping, \code{GOSUB} is used to jump to a subroutine. Subroutine is a little section of a code that serves as a tiny program inside of a program. \code{GOSUB} will remember from which statement in the line you have came from, and will return your program flow to that line when \code{RETURN} statement is encountered. (of course, if \code{RETURN} is used without \code{GOSUB}, program will raise some error) Do note that while you can reserve some portion of a program line as a \code{subroutine}, \tbas{} will not provide local variables and whatnot as all variables in \tbas{} are global, and you can just \code{GOTO} out of a subroutine to anywhere you desire and wreak havoc \emph{if you really want to}. + +The \code{ON} statement provides alternative branching construct. You can enter multiple line numbers and let your variable (or mathematical expression) to choose which index of line numbers to \code{GOTO}- or \code{GOSUB} into. + +The \code{IF-THEN-ELSE} lets you to conditionally select which of the two branches to execute. + +The \code{FOR-NEXT} lets you to loop a portion of a program while automatically counting your chosen variable up or down. diff --git a/assets/tbas/doc/intro.tex b/assets/tbas/doc/intro.tex index 13fc2bb..3799262 100644 --- a/assets/tbas/doc/intro.tex +++ b/assets/tbas/doc/intro.tex @@ -1,5 +1,7 @@ -\tbas{} is a BASIC dialect and its interpreter. \tbas{} emulates most of the common BASIC syntax while adds more advanced and up-to-date concepts gracefully, such as user-defined function that can \emph{actually} recurse, arbitrary list construction using CONS-operator and some of the features in the realm of functional programming from \code{MAP} and \code{FOLD} to cooking a \code{CURRY}\footnote{definitely not a foodstuff\ldots or maybe}. +\tbas{} is a BASIC dialect and its interpreter. \tbas{} emulates most of the common BASIC syntax while adds more advanced and up-to-date concepts gracefully, such as user-defined function that can \emph{actually} recurse, arbitrary list construction using CONS-operator and some of the features in the realm of functional programming from \code{MAP} and \code{FOLD} to \code{CURRY}-ing a function. This is the documentation for \tbas{} \tbasver{}. +\vfill + \small\emph{Henceforward this documentation will use more friendly and sometimes vulgar language because that's more fun to write!} diff --git a/assets/tbas/doc/langguide.tex b/assets/tbas/doc/langguide.tex index 6c482cc..591a4fe 100644 --- a/assets/tbas/doc/langguide.tex +++ b/assets/tbas/doc/langguide.tex @@ -1,4 +1,7 @@ -Okay, how do we begin\ldots +\quad +\chapterprecishere{``Begin at the beginning'', the King said gravely, ``and go on till you come to the end: then stop.''\par\raggedleft --- \textup{Lewis Carroll, } Alice in Wonderland} + +We'll begin at the beginning; how beginning? This: \begin{lstlisting} 10 PRINT 2+2 @@ -41,11 +44,11 @@ So what the fsck is currying? Consider the following code: 40 PRINT CF(-32) : REM will print 'true' \end{lstlisting} -Here, \code{CF} is a curried function of \code{F}; built-in function \code{CURRY} applies \code{32} to the first parametre of the function \code{F}, which dynamically returns a \code{function} \code{CF(T)=ABS(T)==32}. The fact that \code{CURRY} returns a \emph{function} opens many possibilities, for example, you can create loads of cousin function without making loads of duplicate codes. +Here, \code{CF} is a curried function of \code{F}; built-in function \code{CURRY} applies \code{32} to the first parametre of the function \code{F}, which dynamically returns a \emph{function} of \code{CF(T) = ABS(T) == 32}. The fact that \code{CURRY} 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} -Using all the knowledge we have learned, it should be trivial\footnote{/s} to write a Quicksort algorithm in \tbas, like this: +Using all the knowledge we have learned, it should be trivial\footnote{/s} to write a Quicksort function in \tbas, like this: \begin{lstlisting} 10 DEFUN LESS(P,X)=X

IF LEN(XS)<1 THEN NIL ELSE QSORT(FILTER([K]~>KK>=XS(0),XS)) +%% 100 L=7!9!4!5!2!3!1!8!6!NIL +%% 110 SL=QSORT(L) +%% 120 PRINT L:PRINT SL +%% \end{lstlisting}