mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-07 19:51:51 +09:00
something something basicdoc update
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
\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}}
|
||||
\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: Donald R. Woods, James M. Lyon, \emph{The INTERCAL Programming Language Reference Manual}}}
|
||||
|
||||
This chapter describes the basic concepts of the \tbas\ language.
|
||||
|
||||
@@ -7,17 +7,17 @@ This chapter describes the basic concepts of the \tbas\ language.
|
||||
\section{Values and Types}
|
||||
\label{valuesandtypes}
|
||||
|
||||
BASIC is a \emph{Dynamically Typed Language}, which means variables do not know which group they should barge in; only values of the variable do. In fact, there is no type definition in the language: \emph{we do want our variables to feel themselves awkward.}
|
||||
BASIC is a \emph{Dynamically Typed Language}, which means variables do not know which group they should barge in; only values of the variable do. In fact, there is no type definition in the language: \emph{we do want our variables to feel awkward.}
|
||||
|
||||
There are six basic types: \emph{number}, \emph{boolean}, \emph{string}, \emph{array}, \emph{generator} and \emph{function}.
|
||||
|
||||
\emph{Number} represents real (double-precision floating-point or \emph{actually rational}) numbers. Operations on numbers follow the same rules of the underlying virtual machine\footnote{if you are not a computer person, just disregard}, and such machines must follow the IEEE 754 standard\footnote{ditto.}.
|
||||
\emph{Number} represents real (double-precision floating-point or actually, \emph{rational}) numbers. Operations on numbers follow the same rules of the underlying virtual machine\footnote{if you are not a computer person, disregard}, and such machines must follow the IEEE 754 standard\footnote{ditto.}.
|
||||
|
||||
\emph{Boolean} is the type of the values that is either \codebf{TRUE} or \codebf{FALSE}. Number \codebf{0} and \codebf{FALSE} makes condition \emph{false}. When used in numeric context, \codebf{FALSE} will be interpreted as 0 and \codebf{TRUE} as 1.
|
||||
\emph{Boolean} is type of the value that is either \codebf{TRUE} or \codebf{FALSE}. Number \codebf{0} and \codebf{FALSE} make the condition \emph{false}. When used in numeric context, \codebf{FALSE} will be interpreted as 0 and \codebf{TRUE} as 1.
|
||||
|
||||
\emph{String} represents immutable\footnote{cannot be altered directly} sequences of bytes. However, you can't weave them to make something like \emph{string array}\footnote{future feature\ldots\ maybe\ldots? Probably not\ldots}.
|
||||
\emph{String} represents immutable\footnote{Cannot be altered directly} sequences of bytes. However, you can't weave them to make something like \emph{string array}\footnote{Future feature\ldots\ maybe\ldots? Probably not\ldots}.
|
||||
|
||||
\emph{Array} represents collection of numbers in 1- or more dimensions.
|
||||
\emph{Array} represents a collection of numbers in one or more dimensions.
|
||||
|
||||
\emph{Generator} represents a value that automatically counts up/down whenever they have been called in FOR--NEXT loop.
|
||||
|
||||
@@ -27,9 +27,9 @@ There are six basic types: \emph{number}, \emph{boolean}, \emph{string}, \emph{
|
||||
|
||||
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}.
|
||||
You can dive into other lines 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}.
|
||||
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 BASIC are global, and you can just \code{GOTO} out of a subroutine to anywhere you desire and wreak havoc \emph{if you really wanted 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.
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ This chapter explains implementation details of \tbas\ running on \thismachine.
|
||||
|
||||
\section{Keycodes}
|
||||
|
||||
This is a keycodes recognised by LibGDX, a framework that \thismachine\ runs on.
|
||||
This is a table of keycodes recognised by the LibGDX, a framework that \thismachine\ runs on.
|
||||
|
||||
\begin{longtable}{*{2}{m{\textwidth}}}\hline
|
||||
\endfirsthead
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
\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.
|
||||
\tbas\ is a BASIC dialect and its interpreter. \tbas\ emulates most of the common BASIC syntax while also adding 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.
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ Oh \emph{boy} we just did a computation! It printed out \code{4} which is a corr
|
||||
|
||||
\section[GOTO]{GOTO here and there}
|
||||
|
||||
\code{GOTO} is used a lot in BASIC, and so does in \tbas. \code{GOTO} is a simplest method of diverging a program flow: execute only the some part of the program conditionally and perform a loop.
|
||||
\code{GOTO} is used a lot in BASIC, and so does in \tbas. \code{GOTO} is a simplest method of diverging a program flow: execute only the part of the program conditionally and perform a loop.
|
||||
|
||||
Following program attempts to calculate a square root of the input value, showing how \code{GOTO} can be used in such manner.
|
||||
|
||||
@@ -52,7 +52,7 @@ This program will draw a triangle, where the actual drawing part is on line 100-
|
||||
|
||||
\section[FOR--NEXT Loop]{FOR ever loop NEXT}
|
||||
|
||||
As we've just seen, you can make loops using \code{GOTO}s here and there, but they \emph{totally suck}, too much spaphetti crashes your cerebral cortex faster than \emph{Crash Bandicoot 2}. Fortunately, there's a better way to go about that: the FOR--NEXT loop!
|
||||
As we've just seen, you can make loops using \code{GOTO}s here and there, but they \emph{totally suck}, too much spaghetti crashes your cerebral cortex faster than \emph{Crash Bandicoot 2}. Fortunately, there's a better way to go about that: the FOR--NEXT loop!
|
||||
|
||||
\begin{lstlisting}
|
||||
10 GOTO 1000
|
||||
@@ -97,7 +97,7 @@ Consider the following code:
|
||||
90 NEXT
|
||||
\end{lstlisting}
|
||||
|
||||
Here, we have defined two functions to use in the program: \code{POW2} and \code{DCOS2}. Also observe that functions are defined using variable \code{N}s, but we use them with \code{X} in line 40 and with \code{A} in line 80: yes, functions can have their local name so you don't have to carefully choose which variable name to use in your subroutine.
|
||||
Here, we have defined two functions to use in the program: \code{POW2} and \code{DCOS}. Also observe that functions are defined using variable \code{N}s, but we use them with \code{X} in line 40 and with \code{A} in line 80: yes, functions can have their local name so you don't have to carefully choose which variable name to use in your subroutine.
|
||||
|
||||
Except a function can't have statements that spans 2- or more BASIC lines; but there are ways to get around that, including \code{DO} statement and \emph{functional currying}.
|
||||
|
||||
@@ -116,7 +116,7 @@ But don't get over-excited, as it's super-trivial to create unintentional infini
|
||||
|
||||
(if you tried this and computer becomes unresponsive, hit Ctrl-C to terminate the execution)
|
||||
|
||||
This failed attempt is to create a function that calculates a factorial of \code{N}. It didn't work because there is no \emph{halting condition}: didn't told computer to when to escape from the loop.
|
||||
This failed attempt is to create a function that calculates a factorial of \code{N}. It didn't work because there is no \emph{halting condition}: didn't tell computer to when to escape from the loop.
|
||||
|
||||
$n \times 1$ is always $n$, and $0!$ is $1$, so it would be nice to break out of the loop when \code{N} reaches $0$; here is the modified program:
|
||||
|
||||
@@ -140,7 +140,7 @@ Since \code{IF-THEN-ELSE} can be chained to make third or more conditions --- \c
|
||||
|
||||
\code{MAP} is a \emph{higher-order}\footnote{Higher-order function is a function that takes another function as an argument.} function that takes a function (called \emph{transformation}) and an array to construct a new array that contains old array transformed with given \emph{transformation}.
|
||||
|
||||
Or, think about the old \code{FAC} program before: it only printed out the value of $1!$, $2!$ \ldots\ $10!$. What if we wanted to build an array that contains such values?
|
||||
Or, think about the old \code{FAC} program before: it merely printed out the value of $1!$, $2!$ \ldots\ $10!$. What if we wanted to build an array that contains such values?
|
||||
|
||||
\begin{lstlisting}
|
||||
10 DEFUN FAC(N)=IF N==0 THEN 1 ELSE N*FAC(N-1)
|
||||
@@ -148,7 +148,7 @@ Or, think about the old \code{FAC} program before: it only printed out the value
|
||||
30 PRINT K
|
||||
\end{lstlisting}
|
||||
|
||||
Here, \code{K} will contain the values of $1!$, $2!$ \ldots\ $10!$. We're just printing out the array, but you can make acutual use out of the array.
|
||||
Here, \code{K} will contain the values of $1!$, $2!$ \ldots\ $10!$. Right now we're just printing out the array, but you can make acutual use out of the array.
|
||||
|
||||
\section[Currying]{Haskell Curry Wants to Know Your Location}
|
||||
\label{currying101}
|
||||
|
||||
@@ -11,7 +11,7 @@ In the descriptions of BASIC syntax, these conventions apply.
|
||||
\item \code{IDENTIFIER} --- Replace \emph{identifier} with appropriate metavariable
|
||||
\item \code{[a]} --- Words within square brackets are optional
|
||||
\item \code{\{a|b\}} --- Choose either \code{a} or \code{b}
|
||||
\item \code{[a|b]} --- Optional version of above
|
||||
\item \code{[a|b]} --- Optional version of the above
|
||||
\item \code{a\ldots} --- The preceding entity can be repeated
|
||||
\end{itemlist}
|
||||
|
||||
@@ -46,7 +46,7 @@ String literals take the following form:
|
||||
|
||||
\codeline{\textbf{"} [CHARACTERS] \textbf{"}}
|
||||
|
||||
where \code{CHARACTERS} is a 0 or more repetition of ASCII-printable letters.\footnote{In other words, \code{0x20..0x7E}}
|
||||
where \code{CHARACTERS} is a 1- or more repetition of ASCII-printable letters.\footnote{In other words, \code{0x20..0x7E}}
|
||||
|
||||
To print out graphical letters outside of ASCII-printable, use string concatenation with \code{CHR} function, or use \code{EMIT} function.
|
||||
|
||||
@@ -255,13 +255,13 @@ Code & Operation & Result \\
|
||||
|
||||
Some variables are pre-defined on the language itself and cannot be modified; such variables are called \emph{constants}.
|
||||
|
||||
\begin{tabulary}{\textwidth}{rlL}
|
||||
Name & Type & Value \\
|
||||
\begin{tabulary}{\textwidth}{rllL}
|
||||
Name & Type & Value & Description \\
|
||||
\hline
|
||||
NIL & Array & Empty Array \\
|
||||
PI & Number & $3.141592653589793$ \\
|
||||
TAU & Number & $6.283185307179586$ \\
|
||||
EULER & Number & $2.718281828459045$
|
||||
NIL & Array & Empty Array & Used to construct arbitrary array using CONS-operator \\
|
||||
PI & Number & $3.141592653589793$ & $\pi$ \\
|
||||
TAU & Number & $6.283185307179586$ & $2 \pi$ \\
|
||||
EULER & Number & $2.718281828459045$ & Euler's number $e$ \\
|
||||
\end{tabulary}
|
||||
|
||||
\section{Syntax In EBNF}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
This is a sample program that is the \emph{Hamurabi} game. The original program was on \emph{BASIC Computer Games: Microcomputer Edition} and was translated into \tbas. This game is considered as the great ancestor of the strategy, simulation and city-building games; in fact it's so great it has got its own Wikipedia article.
|
||||
This is a sample program that is the \emph{Hamurabi} game. The original program was on \emph{BASIC Computer Games: Microcomputer Edition} and was translated into \tbas. This game is considered as the grand ancestor of the strategy, simulation and city-building games; in fact it's so great it has got its own Wikipedia article.
|
||||
|
||||
\begin{lstlisting}
|
||||
10 PRINT SPC(32);"HAMURABI"
|
||||
|
||||
Reference in New Issue
Block a user