From c55066b41492e8545528d91dd1d9f893942a5443 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Thu, 24 Dec 2020 17:56:14 +0900 Subject: [PATCH] basic: minor doc update --- assets/disk0/tbas/doc/concepts.tex | 2 +- assets/disk0/tbas/doc/functions.tex | 4 ++-- assets/disk0/tbas/doc/langguide.tex | 34 ++++++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/assets/disk0/tbas/doc/concepts.tex b/assets/disk0/tbas/doc/concepts.tex index c681e56..37334f2 100644 --- a/assets/disk0/tbas/doc/concepts.tex +++ b/assets/disk0/tbas/doc/concepts.tex @@ -19,7 +19,7 @@ There are six basic types: \emph{number}, \emph{boolean}, \emph{string}, \emph{ \emph{Array} represents collection of numbers in 1- or more dimensions. -\emph{Generator} represents a value that automatically counts up/down whenever they have been called in For-Next loop. +\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 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. diff --git a/assets/disk0/tbas/doc/functions.tex b/assets/disk0/tbas/doc/functions.tex index 3f96068..4aae49c 100644 --- a/assets/disk0/tbas/doc/functions.tex +++ b/assets/disk0/tbas/doc/functions.tex @@ -119,7 +119,7 @@ Functions are a form of expression that may taks input arguments surrounded by p \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 + Starts a 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 @@ -141,7 +141,7 @@ Functions are a form of expression that may taks input arguments surrounded by p \end{itemlist} \subsection{NEXT} \codeline{\textbf{NEXT}}\par - Iterates \code{FOR-NEXT} loop and increments the loop variable from the most recent \code{FOR} statement and jumps to that statement. + Iterates FOR--NEXT loop and increments the loop variable from the most recent \code{FOR} statement and jumps to that statement. \subsection{RESTORE} \codeline{\textbf{RESTORE}}\par Resets the \code{DATA} pointer. diff --git a/assets/disk0/tbas/doc/langguide.tex b/assets/disk0/tbas/doc/langguide.tex index 429bac7..b86f4f8 100644 --- a/assets/disk0/tbas/doc/langguide.tex +++ b/assets/disk0/tbas/doc/langguide.tex @@ -16,7 +16,9 @@ Oh \emph{boy} we just did a computation! It printed out \code{4} which is a corr \section[When GOTO Is Bad]{Severe Acute Spaghettification Syndrome} \section[Subroutine with GOSUB]{GOSUB to the rescue!} -\section[FOR-NEXT Loop]{FOR ever loop NEXT} +\section[FOR--NEXT Loop]{FOR ever loop NEXT} + +So you can make a loop using \code{GOTO}s here and there, but they \emph{totally suck}. Fortunately, there's better way to go about that: the FOR--NEXT loop! \begin{lstlisting} 10 FOR I = 1 TO 20 @@ -29,8 +31,38 @@ Oh \emph{boy} we just did a computation! It printed out \code{4} which is a corr \section[Get User INPUT]{Isn't It Nice To Have a Computer That Will Question You?} +What fun is the program if it won't talk with you? You can make that happen with \code{INPUT} statement. + + +\begin{lstlisting} +10 PRINT "WHAT IS YOUR NAME"; +20 INPUT NAME +30 PRINT "HELLO, ";NAME +\end{lstlisting} + +This short program will ask your name, and then it will greet you by the name you told to the computer. + +\section[Function]{Function} + +Consider the following code: + +\begin{lstlisting} +(code with many repeating phrases) +\end{lstlisting} + +As you can clearly see, it has way too many repeating phrase: \code{i'm redundant!} Would it be nice to tidy it up, but much cooler and in \emph{one-liner}? + +Lo and behold, the \code{DEFUN}! You can define a \emph{function} in a single line using it, and it even re-names the variable so you don't have to worry about unintended name collisions like when you were playing with \code{GOSUB}s! + +\begin{lstlisting} +(same code but better) +\end{lstlisting} + + \section[Recursion]{BRB: Bad Recursion BRB: Bad Recursion BRB: Bad Recursion BRB: Bad RecursionBRB: Bad Recursion BRBRangeError: Maximum call stack size exceeded} +But don't get over-excited, as it's super-trivial to create unintentional infinite loop. + \begin{lstlisting} 10 DEFUN ENDLESS(SHIT)=ENDLESS(SHIT) 20 ENDLESS(1)