blob: 580e00f3a955e9f97c4ef4973d500f5fdf58e693 [file] [log] [blame]
swissChili8a4b4ed2021-08-03 19:27:32 -07001\documentclass[letterpaper,11pt,twocolumn]{article}
2\usepackage[top=2cm, bottom=2cm, left=2cm, right=2cm]{geometry}\usepackage[T1]{fontenc}
3\usepackage[utf8]{inputenc}
4\usepackage{lmodern}
5\usepackage{amsmath}
6\usepackage{amsfonts}
7\usepackage{amssymb}
8\usepackage{amsthm}
9\usepackage{graphicx}
10\usepackage{color}
11\usepackage{xcolor}
12\usepackage{url}
13\usepackage{textcomp}
14\usepackage{listings}
15\usepackage{glossaries}
16\usepackage{parskip}
17\usepackage{imakeidx}
18\usepackage[normalem]{ulem}
19
20\title{Bluejay Lisp Reference}
21\author{swissChili}
22\date{Development Version: \today}
23
24\newcommand{\startexplanation}{$\triangleright$\hskip1.4ex}
25\newcommand{\definition}[2]{#1
26\begin{quote}%
27 \startexplanation#2%
28\end{quote}}
29\newcommand{\plus}{\texttt{+}}
30\newcommand{\pluses}[1]{\plus{}#1\plus{}}
31\newcommand{\earmuff}{\texttt{*}}
32\newcommand{\earmuffs}[1]{\earmuff{}#1\earmuff{}}
33\newcommand{\func}[1]{\text{$_f$\textbf{#1}}}
34\newcommand{\mac}[1]{\text{$_m$\textbf{#1}}}
35\newcommand{\reader}[1]{\text{$_r$\textbf{#1}}}
36\newcommand{\const}[1]{\text{$_c$\textbf{#1}}}
37\newcommand{\var}[1]{\text{$_v$\textbf{#1}}}
38\newcommand{\param}[1]{\textit{#1}}
39\newcommand{\ret}[1]{\uline{#1}}
40\newcommand{\type}[1]{\text{$_t$\textbf{#1}}}
41\newcommand{\more}{ \ldots}
42\newcommand{\T}{\texttt{t}}
43\newcommand{\nil}{\texttt{nil}}
44\newcommand{\default}[1]{\text{\textsubscript{
45 \setlength{\fboxsep}{1pt}\setlength{\fboxrule}{0.2bp}%
46 \fbox{#1}}}}
47\newcommand{\opt}[2]{\text{$[$}\param{#1}\default{#2}\text{$]$}}
48\newcommand{\mut}[1]{\text{$\widetilde{#1}$}}
swissChilia89ee442021-08-04 20:54:51 -070049\newcommand{\mighteval}[1]{\text{$\widehat{#1}$}}
swissChili8a4b4ed2021-08-03 19:27:32 -070050\newcommand{\super}[1]{\text{$ ^{#1} $}}
51
52\newcommand{\optlist}[1]{\text{\(
53 \left\{
54 \begin{array}{l}
55 #1
56 \end{array}
57 \right\}
58\)}}
59
60\makeindex
61\makeglossaries
62
63\newglossaryentry{closure}{name={closure},description={A \type{function-object} that captures certain variables from its defining context}}
64
65\newglossaryentry{lexical-scope}{name={lexical scope},description={A method of scoping where the values in scope at a given time are determined by the static content of the source program, not by the state of the callstack or other execution details. This allows for example closures to \gls{closure}s to capture some of the state of their defining context}}
66
67\newglossaryentry{truthy}{name={truthy},description={A value that is not \nil}}
68
69\begin{document}
70
71\maketitle
72\tableofcontents
73
74\section{Introduction}
75
76This document provides a brief reference to the Bluejay Lisp language and standard library. It documents every currently valid function, macro, reader macro, and special form supported by the compiler.
77
78\subsection{Typography}
79
80The following text styles and symbols are used within this document to indicate particular values or meanings:
81
swissChilia89ee442021-08-04 20:54:51 -070082\begin{tabular}[t]{p{0.2\linewidth} p{0.64\linewidth}}
swissChili8a4b4ed2021-08-03 19:27:32 -070083 \func{cons} & A function ``cons.'' \\
84 \const{\plus{}foo\plus} & A constant ``\plus{}foo\plus.'' \\
85 \var{\earmuff{}bar\earmuff} & A global variable ``\earmuff{}bar\earmuff''. \\
86 \reader{baz} & A reader macro ``baz.'' \\
87 \mac{quux} & A macro ``quux.'' \\
swissChilia89ee442021-08-04 20:54:51 -070088 \param{parameter} & A function argument ``parameter'' \\
swissChili8a4b4ed2021-08-03 19:27:32 -070089 \opt{var}{123} & An optional function argument ``var'' with the default value ``123.'' \\
90 \param{args}\more & ``args'' represents the rest of the items in the list. \\
91 \mut{\param{mut}} & A function argument ``mut'' that might be mutated. \\
swissChilia89ee442021-08-04 20:54:51 -070092 \mighteval{\param{maybe}} & ``maybe'' may or may not be evaluated. \\
swissChili8a4b4ed2021-08-03 19:27:32 -070093 \ret{value} & Indicates that a form will evaluate to ``value''. \\
94 \type{integer} & The type ``integer''. \\
95 \optlist{\text{a}\\\text{b}} & One of ``a'' or ``b.''
96\end{tabular}
97
98\section{Primitives}
99
100\subsection{Type Predicates}
101
102\definition{
103 (\optlist{
104 \func{nilp} \text{ or } \func{not} \\
105 \func{integerp}
106 } \param{value})\index{nilp}\index{not}
107}{
108 \ret{\T} if \param{value} is of the specified type, \ret{\nil} otherwise.
109}
110
111\subsection{Definitions and Variables}
112
113\definition{
114 (\mac{defun} \param{name} (\param{args}\more) \param{body}\more)\index{defun} \\
115 (\mac{defmacro} \param{name} (\param{args}\more) \param{body}\more)\index{defmacro}
116}{
117 Define a function or macro respectively, taking \param{args} arguments and evaluating \param{body} in turn, finally evaluating to \ret{the final entry in \param{body}} or \ret{\nil} if \param{body} is empty.
118}
119
120\definition{
121 (\mac{let1} (\param{variable} \param{form}) \param{body}\more)\index{let1}
122}{
123 First evaluate \param{form}, binding it to \param{variable}. Then evaluate \param{body}, finally evaluating to \ret{the final entry in \param{body}} or \ret{\nil} if \param{body} is empty. \param{variable} is no longer in scope after this form ends.
124}
125
126\definition{
127 \reader{\textquotesingle}\param{value} \\
128 (\mac{quote} \param{value})\index{quote}
129}{
130 \ret{Return \param{value}} as-is, without evaluating it.
131}
132
133\subsection{Control Flow}
134
135\definition{
136 (\mac{if} \param{predicate} \param{then} \opt{otherwise}{nil})\index{if} \\
137 (\mac{when} \param{predicate} \param{then\more})\index{when} \\
138 (\mac{unless} \param{predicate} \param{otherwise\more})\index{unless}
139}{
140 First evaluate \param{predicate}. If it is \gls{truthy} evaluate and return \ret{\param{then}}, otherwise \ret{\param{otherwise}}. If either is not provided return \ret{\nil}.
141}
142
143\definition{
144 (\mac{progn} \opt{forms\more}{nil})\index{progn}
145}{
146 Evaluate \param{forms} from first to last, finally returning \ret{the last form}.
147}
148
swissChilia89ee442021-08-04 20:54:51 -0700149\definition{
150 (\mac{and} \param{first} \param{\mighteval{rest}}\more)\index{and} \\
151 (\mac{or} \param{first} \param{\mighteval{rest}}\more)\index{or}
152}{
153 Short circuiting $\land$ and $\lor$, respectively. Return the first value that is \nil{} or truthy, respectively, or the last value if all are truthy/\nil{}.
154}
155
swissChili8a4b4ed2021-08-03 19:27:32 -0700156\section{Numbers}
157
158\subsection{Integers}
159
160\definition{
161 (\func{$+$} \param{a b})\index{+} \\
162 (\func{$-$} \param{a b})\index{-} \\
163 (\func{$*$} \param{a b})\index{*} \\
164 (\func{$/$} \param{a b})\index{/}
165}{
166 The \ret{sum, difference, product, or quotient} of \param{a} and \param{b} as an \type{integer}.
167}
168
169\definition{
170 (\func{=} \param{a b})
171}{
172 \ret{\T} if \param{a} and \param{b} hold the same \type{integer} value, \ret{\nil} otherwise.
173}
174
175\section{Function Manipulation}
176
177\definition{
swissChilia89ee442021-08-04 20:54:51 -0700178 (\func{funcall} \param{args}\more)\index{funcall} \\
swissChili8a4b4ed2021-08-03 19:27:32 -0700179 (\func{apply} \param{function} \param{args})\index{apply}
180}{
181 Call the \type{closure} or \type{function-object} \param{function} with \param{args} and evaluate to \ret{its result}. An error occurs if \param{args} are not acceptable.
182}
183
184\definition{
185 (\mac{function} \param{function-name})\index{function} \\
186 \reader{\#\textquotesingle}\param{function-name}\index{\#\textquotesingle}
187}{
swissChilia89ee442021-08-04 20:54:51 -0700188 Create a \ret{\type{function-object} from an existing function or macro}. \param{function} must be a symbol literal at compile time.
swissChili8a4b4ed2021-08-03 19:27:32 -0700189}
190
191\definition{
192 (\func{lambda} (\param{args}\more) \param{body}\more)\index{lambda}
193}{
194 Create a \ret{lexically-scoped \type{\gls{closure}}} taking \param{args} and evaluating to \param{body}.
195}
196
197\definition{
198 (\func{eval} \param{form})\index{eval}
199}{
200 Evaluate and return \ret{\param{form}} in the current global environment. The evaluated form does not use \gls{lexical-scope}.
201}
202
203\section{Lists}
204
205\subsection{Creating Lists}
206
207\definition{
208 (\func{cons} \param{a} \param{b})\index{cons}
209}{
210 Join \param{a} and \param{b} into a \ret{\type{cons} pair}.
211}
212
213\definition{
214 (\func{list} \param{values}\more)\index{list}
215}{
216 Construct a \ret{\type{cons}-list of \param{values}}.
217}
218
219\subsection{Deconstructing Lists}
220
221\definition{
222 (\func{length} \param{list})\index{list}
223}{
224 Return the \ret{length of \param{list}} if it is a \type{cons}-list, \nil{} otherwise.
225}
226
227\definition{
228 (\func{car} \param{pair})\index{car} \\
229 (\func{cdr} \param{pair})\index{cdr}
230}{
231 Return the \ret{first or second item} of \type{cons} \param{pair}, respectively.
232}
233
234\definition{
235 (\optlist{
236 \func{caar}\\
237 \func{cadr}\\
238 \func{caddr}\\
239 \func{cadar}\\
240 \func{caddar}
241 } \param{val})
242}{
243 Behave like a combination of \func{car} and \func{cdr} would.
244}
245
246\definition{
247 (\func{elt} \param{list} \param{n})\index{elt}
248}{
249 Return the \ret{\param{n}\super{th} element of \param{list}}, starting from 0, or \ret{\nil} if \param{n} $ \ge $ (\func{length} \param{list}) or \param{list} is not a \type{cons}-list or \param{n} is not an \type{integer}.
250}
251
252\subsection{Operating on Lists}
253
254\definition{
255 (\func{mapcar} \param{fun} \param{list})\index{mapcar}
256}{
257 Apply \param{fun} to each element of \param{list}, returning a \ret{new \type{cons}-list} containing the results of the respective applications of \param{fun}.
258}
259
260\definition{
261 (\optlist{\func{remove-if}\\\func{remove-if-not}} \param{predicate} \param{list})\index{remove-if}\index{remove-if-not}
262}{
263 Return a \ret{new \type{cons}-list} of all the items of \param{list} that either do not or do satisfy \param{predicate}, respectively.
264}
265
266\definition{
267 (\func{reduce} \param{fun} \param{list} \opt{initial-value}{\nil})
268}{
269 Apply \param{fun} to two arguments at a time, starting with \param{initial-value} and (\func{car} \param{list}) and continuing with the result of the previous invocation and the successive element of \param{list}. Return \ret{the result of the final invocation}, or \ret{\param{initial-value}} if \param{list} is empty.
270}
271
272\section{Input \& Output}
273
274\definition{
275 (\func{print} \param{value})\index{print}
276}{
277 Print \param{value} to standard output. Return \ret{\nil}.
278}
279
280\definition{
281 (\func{read})\index{read}
282}{
283 Read and return an \ret{S-expression} from standard input
284}
285
286\subsection{Loading Programs}
287
288\definition{
289 \const{\pluses{current-file}}\index{\pluses{current-file}}
290}{
291 The current file being compiled, or \nil{} if not compiling a file.
292}
293
294\definition{
295 (\func{load} \param{lisp-file})\index{load}
296}{
297 Load and evaluate \type{string} \param{lisp-file} as a local path relative to the current file, or the current working directory if not compiling a file. Return \ret{\nil}.
298}
299
300\printindex
301
302\printglossaries
303
304\end{document}