basic: adding some inspirational quotes to the manual

This commit is contained in:
minjaesong
2020-12-22 10:49:39 +09:00
parent 47f5b4d9d0
commit 443b5ba31d
3 changed files with 39 additions and 7 deletions

View File

@@ -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.

View File

@@ -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!}

View File

@@ -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<P
@@ -56,4 +59,14 @@ Using all the knowledge we have learned, it should be trivial\footnote{/s} to wr
120 PRINT L:PRINT SL
\end{lstlisting}
Line 10--12 implements quicksort algorithm. \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}}, then using curried version of \code{LESS} and \code{GTEQ} to move values lesser than pivot 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{XS(0)} simply fetches a head-elemement of \code{XS}. \code{XS(0)!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 using head-element of array \code{XS}\footnote{stands for \emph{X's}}, then using curried version of \code{LESS} and \code{GTEQ} to move values lesser than pivot 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{XS(0)} simply fetches a head-elemement of \code{XS}. \code{XS(0)!NIL} creates a single-element array contains \code{XS(0)}.
%Uncomment this if you finally decided to support a closure%
%% Using \emph{closure}, the definition of \code{QSORT} can be \emph{even more cryptic}:
%%
%% \begin{lstlisting}
%% 10 QSORT=[XS]~>IF LEN(XS)<1 THEN NIL ELSE QSORT(FILTER([K]~>K<XS(0),XS)) # XS(0)!NIL # QSORT(FILTER([K]~>K>=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}