mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-07 19:51:51 +09:00
basic: minor doc update
This commit is contained in:
@@ -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.
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user