basicdoc: function chapter is done

This commit is contained in:
minjaesong
2020-12-22 23:48:48 +09:00
parent 0b67613d90
commit 68b2b70ca0
4 changed files with 51 additions and 27 deletions

View File

@@ -35,7 +35,8 @@ Functions are a form of expression that may taks input arguments surrounded by p
\codeline{Y \textbf{= FIX(}X\textbf{)}}\par
Returns integer value of \code{X}, truncated towards zero.
\subsection{FLOOR, INT}
\codeline{Y \textbf{=} \{\textbf{FLOOR}|\textbf{INT}\}\textbf{(}X\textbf{)}}\par
\codeline{Y \textbf{= FLOOR(}X\textbf{)}}
\codeline{Y \textbf{= INT(}X\textbf{)}}\par
Returns integer value of \code{X}, truncated towards negative infinity.
\subsection{LEN}
\codeline{Y \textbf{= LEN(}X\textbf{)}}\par
@@ -84,11 +85,11 @@ Functions are a form of expression that may taks input arguments surrounded by p
\section{Output}
\subsection{EMIT}
\codeline{\textbf{EMIT(}EXPR [\{\textbf{,}|\textbf{;}\} EXPR]...\textbf{)}}\par
\codeline{\textbf{EMIT(}EXPR [\{\textbf{,}|\textbf{;}\} EXPR]\ldots\textbf{)}}\par
Prints out characters corresponding to given number on the code page being used.\par
\code{EXPR} is numeric expression.
\subsection{PRINT}
\codeline{\textbf{PRINT(}EXPR [\{\textbf{,}|\textbf{;}\} EXPR]...\textbf{)}}\par
\codeline{\textbf{PRINT(}EXPR [\{\textbf{,}|\textbf{;}\} EXPR]\ldots\textbf{)}}\par
Prints out given string expressions.\par
\code{EXPR} is a string, numeric expression, or array.\par
\code{PRINT} is one of the few function that differentiates two style of argument separator: \codebf{;} will simply concatenate two expressions (unlike traditional BASIC, numbers will not have surrounding spaces), \codebf{,} tabulates the expressions.
@@ -99,11 +100,11 @@ Functions are a form of expression that may taks input arguments surrounded by p
\codeline{\textbf{CLEAR}}\par
Clears all declared variables.
\subsection{DATA}
\codeline{\textbf{DATA} CONST0 [\textbf{,} CONST1]...}\par
\codeline{\textbf{DATA} CONST0 [\textbf{,} CONST1]\ldots}\par
Adds data that can be read by \code{READ} function.
\subsubsection*{Notes}
\begin{itemlist}
\item \code{DATA} declarations need not be reacheable in the program flow
\item \code{DATA} declarations need not be reacheable in the program flow.
\end{itemlist}
\subsection{END}
\codeline{\textbf{END}}\par
@@ -129,7 +130,7 @@ Functions are a form of expression that may taks input arguments surrounded by p
Puts a name onto the line numeber the statement is located. Jumping to the \code{NAME}
\subsubsection*{Notes}
\begin{itemlist}
\item \code{NAME} must be a valid variable name
\item \code{NAME} must be a valid variable name.
\end{itemlist}
\subsection{NEXT}
\codeline{\textbf{NEXT}}\par
@@ -150,22 +151,22 @@ Functions are a form of expression that may taks input arguments surrounded by p
\codeline{CHAR \textbf{= CHR(}X\textbf{)}}\par
Returns the character with code point of \code{X}. Code point is a numeric expression in the range of $[0-255]$.
\subsection{LEFT}
\codeline{SUBSTR \textbf{= LEFT(}STR\textbf{,}NUM\_CHARS\textbf{)}}\par
\codeline{SUBSTR \textbf{= LEFT(}STR \textbf{,} NUM\_CHARS\textbf{)}}\par
Returns the leftmost \code{NUM\_CHARS} characters of \code{STR}.
\subsection{MID}
\codeline{SUBSTR \textbf{= MID(}STR\textbf{,}POSITION\textbf{,}LENGTH\textbf{)}}\par
\codeline{SUBSTR \textbf{= MID(}STR \textbf{,} POSITION \textbf{,} LENGTH\textbf{)}}\par
Returns a substring of \code{STR} starting at \code{POSITION} with specified \code{LENGTH}.\par
When \code{OPTIONBASE 1} is specified, the position starts from 1; otherwise it will start from 0.
\subsection{RIGHT}
\codeline{SUBSTR \textbf{= RIGHT(}STR\textbf{,}NUM\_CHARS\textbf{)}}\par
Returns the rightmost \code{NUM\_CHARS} characters of \code{STR}.
\subsection{SPC}
\codeline{STR \textbf{= SPC(}STR\textbf{,}NUM\_CHARS\textbf{)}}\par
\codeline{STR \textbf{= SPC(}STR \textbf{,} NUM\_CHARS\textbf{)}}\par
Returns a string of \code{NUM\_CHARS} spaces.
\section{Graphics}
\subsection{PLOT}
\codeline{\textbf{PLOT(}X\_POS\textbf{,}Y\_POS\textbf{,}COLOUR\textbf{)}}\par
\codeline{\textbf{PLOT(}X\_POS \textbf{,} Y\_POS \textbf{,} COLOUR\textbf{)}}\par
Plots a pixel to the framebuffer of the display, at XY-position of \code{X\_POS} and \code{Y\_POS}, with colour of \code{COLOUR}.\par
Top-left corner of the pixel will be 1 if \code{OPTIONBASE 1} is specified; otherwise it will be 0.
@@ -186,17 +187,37 @@ Functions are a form of expression that may taks input arguments surrounded by p
\section{System}
\subsection{PEEK}
\codeline{BYTE \textbf{= PEEK(}MEMADDR\textbf{)}}\par
Returns whatever the value stored in the \code{MEMADDR} of the scratchpad-memory.\par
\codeline{BYTE \textbf{= PEEK(}MEM\_ADDR\textbf{)}}\par
Returns whatever the value stored in the \code{MEM\_ADDR} of the scratchpad-memory.\par
Address mirroring, illegal access, etc. are entirely up to the virtual machine which the BASIC interpreter is running on.
\subsection{POKE}
\codeline{\textbf{POKE(}MEMADDR\textbf{,}BYTE\textbf{)}}\par
Puts a \code{BYTE} into the \code{MEMADDR} of the scratchpad-memory.
\codeline{\textbf{POKE(}MEM\_ADDR \textbf{,} BYTE\textbf{)}}\par
Puts a \code{BYTE} into the \code{MEM\_ADDR} of the scratchpad-memory.
\section{Higher-order Function}
\subsection{CURRY}
\subsection{DO}
\codeline{\textbf{DO(}EXPR0 [\textbf{;} EXPR1]\ldots\textbf{)}}\par
Executes \code{EXPRn}s sequentially.
\subsection{FILTER}
\codeline{NEWLIST \textbf{= FILTER(}FUNCTION \textbf{,} ITERABLE\textbf{)}}\par
Returns an array of values from the \code{ITERABLE} that passes the given function. i.e. values that makes \code{FUNCTION(VALUE\_FROM\_ITERABLE)} true.
\subsubsection*{Parameters}
\begin{itemlist}
\item \code{FUNCTION} is a user-defined function with single parameter.
\item \code{ITERABLE} is either an array or a generator.
\end{itemlist}
\subsection{FOLD}
\codeline{NEWVALUE \textbf{= FOLD(}FUNCTION \textbf{,} INIT\_VALUE \textbf{,} ITERABLE\textbf{)}}\par
Iteratively applies given function with accumulator and the value from the \code{ITERABLE}, returning the final accumulator. Accumulator will be set to \code{INIT\_VALUE} before iterating over the iterable. In the first execution, the accumulator will be set to \code{ACC=FUNCTION(ACC,ITERABLE(0))}, and the execution will continue to remaining values within the iterable until all values are consumed. The \code{ITERABLE} will not be modified after the execution.
\subsubsection*{Parameters}
\begin{itemlist}
\item \code{FUNCTION} is a user-defined function with two parameters: first parameter being accumulator and second being a value.
\end{itemlist}
\subsection{MAP}
\codeline{NEWLIST \textbf{= MAP(}FUNCTION \textbf{,} ITERABLE\textbf{)}}\par
Applies given function onto the every element in the iterable, and returns an array that contains such items. i.e. returns tranformation of \code{ITERABLE} of which the transformation is \code{FUNCTION}. The \code{ITERABLE} will not be modified after the execution.
\subsubsection*{Parameters}
\begin{itemlist}
\item \code{FUNCTION} is a user-defined function with single parameter.
\end{itemlist}

View File

@@ -34,6 +34,7 @@ Oh \emph{boy} we just did a computation! It printed out \code{4} which is a corr
\end{lstlisting}
\section[Currying]{Haskell Curry Wants to Know Your Location}
\label{currying101}
So what the fsck is currying? Consider the following code:

View File

@@ -12,7 +12,7 @@ In the descriptions of BASIC syntax, these conventions apply.
\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...} --- The preceding entity can be repeated
\item \code{a\ldots} --- The preceding entity can be repeated
\end{itemlist}
\section{Definitions}
@@ -23,7 +23,7 @@ A \emph{Line Number} is an integer within the range of \intrange{}.
A \emph{Statement} is special form of code which has special meaning. A program line can be composed of 1 or more statements, separated by colons. For the details of statements available in \tbas , see \ref{statements}.
\codeline{STATEMENT [: STATEMENT]...}
\codeline{STATEMENT [: STATEMENT]\ldots}
An \emph{Expression} is rather normal program lines, e.g. mathematical equations and function calles. The expression takes one of the following forms. For the details of functions available in \tbas , see \ref{functions}.
@@ -37,7 +37,7 @@ An \emph{Expression} is rather normal program lines, e.g. mathematical equations
An \emph{Array} takes following form:
\codeline{ARRAY\_NAME \textbf{(} EXPRESSION [\textbf{,} EXPRESSION]... \textbf{)}}
\codeline{ARRAY\_NAME \textbf{(} EXPRESSION [\textbf{,} EXPRESSION]\ldots\ \textbf{)}}
\section{Literals}
\subsection{String Literals}
@@ -54,9 +54,9 @@ To print out graphical letters outside of ASCII-printable, use string concatenat
Numeric literals take one of the following forms:
\codeline{[\textbf{+}|\textbf{-}][\textbf{0}|\textbf{1}|\textbf{2}|\textbf{3}|\textbf{4}|\textbf{5}|\textbf{6}|\textbf{7}|\textbf{8}|\textbf{9}]... [\textbf{.}][\textbf{0}|\textbf{1}|\textbf{2}|\textbf{3}|\textbf{4}|\textbf{5}|\textbf{6}|\textbf{7}|\textbf{8}|\textbf{9}]...}\\
\codeline{\textbf{0}\{\textbf{x}|\textbf{X}\}[\textbf{0}|\textbf{1}|\textbf{2}|\textbf{3}|\textbf{4}|\textbf{5}|\textbf{6}|\textbf{7}|\textbf{8}|\textbf{9}]...}\\
\codeline{\textbf{0}\{\textbf{b}|\textbf{B}\}[\textbf{0}|\textbf{1}|\textbf{2}|\textbf{3}|\textbf{4}|\textbf{5}|\textbf{6}|\textbf{7}|\textbf{8}|\textbf{9}]...}
\codeline{[\textbf{+}|\textbf{-}][\textbf{0}|\textbf{1}|\textbf{2}|\textbf{3}|\textbf{4}|\textbf{5}|\textbf{6}|\textbf{7}|\textbf{8}|\textbf{9}]\ldots\ [\textbf{.}][\textbf{0}|\textbf{1}|\textbf{2}|\textbf{3}|\textbf{4}|\textbf{5}|\textbf{6}|\textbf{7}|\textbf{8}|\textbf{9}]\ldots}\\
\codeline{\textbf{0}\{\textbf{x}|\textbf{X}\}[\textbf{0}|\textbf{1}|\textbf{2}|\textbf{3}|\textbf{4}|\textbf{5}|\textbf{6}|\textbf{7}|\textbf{8}|\textbf{9}]\ldots}\\
\codeline{\textbf{0}\{\textbf{b}|\textbf{B}\}[\textbf{0}|\textbf{1}|\textbf{2}|\textbf{3}|\textbf{4}|\textbf{5}|\textbf{6}|\textbf{7}|\textbf{8}|\textbf{9}]\ldots}
Hexadecimal and binary literals are always interpreted as \emph{unsigned} integers. They must range between \intrange{}.
@@ -227,6 +227,8 @@ Code & Operation & Result \\
%{[}\emph{x},\,\emph{y}\ldots{]} \basicclosure{} \emph{e} & Closure & Creates a closure (anonymous function) from one or more parameters \emph{x},\,\emph{y}\ldots\ and an expression \emph{e} \\
\end{tabulary}
\emph{Currying} is an operation that returns derivative of the function that has given value applied to its first parameter.\footnote{Do \emph{not} believe in that this is \emph{the} definition of currying. In the wild, currying is applied to cascades of \lambda-expressions and the behaviour is different to \tbas{}'s, even though it seems equivalent if you compare the function that two curries would produce.} See \ref{currying101} for tutorials.
\section{Syntax In EBNF}
If you're \emph{that} into the language theory of computer science, texts above are just waste of bytes/inks/pixel-spaces/whatever; this little section should be more than enough!

View File

@@ -18,11 +18,11 @@ If \code{TRUTH\_VALUE} is truthy, executes \code{TRUE\_EXPRESSION}; if \code{TRU
\section{ON}
\codeline{\textbf{ON} INDEX\_EXPRESSION \{\textbf{GOTO}|\textbf{GOSUB}\} LINE0 [\textbf{,} LINE1]...}
\codeline{\textbf{ON} INDEX\_EXPRESSION \{\textbf{GOTO}|\textbf{GOSUB}\} LINE0 [\textbf{,} LINE1]\ldots}
Jumps to \code{INDEX\_EXPRESSION}-th line number in the argements. If \code{INDEX\_EXPRESSION} is outside of range of the arguments, no jump will be performed.
\subsubsection*{parameters}
\subsubsection*{Parameters}
\begin{itemlist}
\item \code{LINEn} can be a number, numeric expression (aka equations) or a line label.
@@ -33,15 +33,15 @@ Jumps to \code{INDEX\_EXPRESSION}-th line number in the argements. If \code{INDE
\emph{There it is, the} DEFUN. \emph{All those new-fangled parser\footnote{a computer program that translates program code entered by you into some data bits that only it can understand} and paradigms\footnote{a guidance to in which way you must think to assimilate your brain into the computer-overlord} are tied to this very statement on \tbas{}, and only Wally knows its secrets\ldots}
\codeline{\textbf{DEFUN} NAME \textbf{(} [ARGS0 [\textbf{,} ARGS1]...] \textbf{)} \textbf{=} EXPRESSION }
\codeline{\textbf{DEFUN} NAME \textbf{(} [ARGS0 [\textbf{,} ARGS1]\ldots] \textbf{)} \textbf{=} EXPRESSION }
With the aid of other statements\footnote{Actually, only the IF is useful, unless you want to \emph{transcend} from the \emph{dung} of mortality by using DEFUN within DEFUN (a little modification of the source code is required)} and functions, DEFUN will allow you to ascend from traditional BASIC and do godly things such as \emph{recursion}\footnote{see recursion} and \emph{functional programming}.
Oh, and you can define your own function, in traditional \code{DEF FN} sense.
\subsubsection*{parameters}
\subsubsection*{Parameters}
\begin{itemlist}
\item \code{NAME} must be a valid variable name
\item \code{ARGSn} must be valid variable names, but can be a name of variables already used within the BASIC program; their value will not be affected nor be used
\item \code{NAME} must be a valid variable name.
\item \code{ARGSn} must be valid variable names, but can be a name of variables already used within the BASIC program; their value will not be affected nor be used.
\end{itemlist}