swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 1 | \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 |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 26 | \begin{quote}% |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 27 | \startexplanation#2% |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 28 | \end{quote}} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 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{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 45 | \setlength{\fboxsep}{1pt}\setlength{\fboxrule}{0.2bp}% |
| 46 | \fbox{#1}}}} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 47 | \newcommand{\opt}[2]{\text{$[$}\param{#1}\default{#2}\text{$]$}} |
| 48 | \newcommand{\mut}[1]{\text{$\widetilde{#1}$}} |
swissChili | a89ee44 | 2021-08-04 20:54:51 -0700 | [diff] [blame] | 49 | \newcommand{\mighteval}[1]{\text{$\widehat{#1}$}} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 50 | \newcommand{\super}[1]{\text{$ ^{#1} $}} |
| 51 | |
| 52 | \newcommand{\optlist}[1]{\text{\( |
| 53 | \left\{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 54 | \begin{array}{l} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 55 | #1 |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 56 | \end{array} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 57 | \right\} |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 58 | \)}} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 59 | |
| 60 | \makeindex |
| 61 | \makeglossaries |
| 62 | |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 63 | \newglossaryentry{closure}{name={closure},description={A |
| 64 | \type{function-object} that captures certain variables from its |
| 65 | defining context}} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 66 | |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 67 | \newglossaryentry{lexical-scope}{name={lexical scope},description={A |
| 68 | method of scoping where the values in scope at a given time are |
| 69 | determined by the static content of the source program, not by the |
| 70 | state of the callstack or other execution details. This allows for |
| 71 | example closures to \gls{closure}s to capture some of the state of |
| 72 | their defining context}} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 73 | |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 74 | \newglossaryentry{truthy}{name={truthy},description={A value that is |
| 75 | not \nil}} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 76 | |
| 77 | \begin{document} |
| 78 | |
| 79 | \maketitle |
| 80 | \tableofcontents |
| 81 | |
| 82 | \section{Introduction} |
| 83 | |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 84 | This document provides a brief reference to the Bluejay Lisp language |
| 85 | and standard library. It documents every currently valid function, |
| 86 | macro, reader macro, and special form supported by the compiler. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 87 | |
| 88 | \subsection{Typography} |
| 89 | |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 90 | The following text styles and symbols are used within this document to |
| 91 | indicate particular values or meanings: |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 92 | |
swissChili | a89ee44 | 2021-08-04 20:54:51 -0700 | [diff] [blame] | 93 | \begin{tabular}[t]{p{0.2\linewidth} p{0.64\linewidth}} |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 94 | \func{cons} & A function ``cons.'' \\ |
| 95 | \const{\plus{}foo\plus} & A constant ``\plus{}foo\plus.'' \\ |
| 96 | \var{\earmuff{}bar\earmuff} & A global variable ``\earmuff{}bar\earmuff''. \\ |
| 97 | \reader{baz} & A reader macro ``baz.'' \\ |
| 98 | \mac{quux} & A macro ``quux.'' \\ |
| 99 | \param{parameter} & A function argument ``parameter'' \\ |
| 100 | \opt{var}{123} & An optional function argument ``var'' with the default value ``123.'' \\ |
| 101 | \param{args}\more & ``args'' represents the rest of the items in the list. \\ |
| 102 | \mut{\param{mut}} & A function argument ``mut'' that might be mutated. \\ |
| 103 | \mighteval{\param{maybe}} & ``maybe'' may or may not be evaluated. \\ |
| 104 | \ret{value} & Indicates that a form will evaluate to ``value''. \\ |
| 105 | \type{integer} & The type ``integer''. \\ |
| 106 | \optlist{\text{a}\\\text{b}} & One of ``a'' or ``b.'' |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 107 | \end{tabular} |
| 108 | |
| 109 | \section{Primitives} |
| 110 | |
| 111 | \subsection{Type Predicates} |
| 112 | |
| 113 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 114 | (\optlist{ |
| 115 | \func{nilp} \text{ or } \func{not} \\ |
| 116 | \func{integerp} |
| 117 | } \param{value})\index{nilp}\index{not} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 118 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 119 | \ret{\T} if \param{value} is of the specified type, \ret{\nil} |
| 120 | otherwise. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | \subsection{Definitions and Variables} |
| 124 | |
| 125 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 126 | (\mac{defun} \param{name} (\param{args}\more) \param{body}\more)\index{defun} \\ |
| 127 | (\mac{defmacro} \param{name} (\param{args}\more) \param{body}\more)\index{defmacro} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 128 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 129 | Define a function or macro respectively, taking \param{args} |
| 130 | arguments and evaluating \param{body} in turn, finally evaluating to |
| 131 | \ret{the final entry in \param{body}} or \ret{\nil} if \param{body} |
| 132 | is empty. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 136 | (\mac{let1} (\param{variable} \param{form}) \param{body}\more)\index{let1} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 137 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 138 | First evaluate \param{form}, binding it to \param{variable}. Then |
| 139 | evaluate \param{body}, finally evaluating to \ret{the final entry in |
| 140 | \param{body}} or \ret{\nil} if \param{body} is |
| 141 | empty. \param{variable} is no longer in scope after this form ends. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 145 | \reader{\textquotesingle}\param{value} \\ |
| 146 | (\mac{quote} \param{value})\index{quote} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 147 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 148 | \ret{Return \param{value}} as-is, without evaluating it. |
| 149 | } |
| 150 | |
| 151 | \definition{ |
| 152 | \reader{\`}\param{value} \\ |
| 153 | (\mac{backquote} \param{value})\index{backquote}\index{\`} |
| 154 | }{ |
| 155 | Return \ret{\param{value}} as-is, except for any \mac{unquote} |
| 156 | and \mac{unquote-splice} forms (and their reader-macro equivalents). |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 157 | } |
| 158 | |
swissChili | 3f7f584 | 2021-08-08 17:13:45 -0700 | [diff] [blame^] | 159 | \definition{ |
| 160 | \reader{,}\param{value} \\ |
| 161 | (\mac{unquote} \param{value}) \\ |
| 162 | \reader{,\texttt{@}}\param{value} \\ |
| 163 | (\mac{unquote-splice} \param{value}) |
| 164 | \index{unquote}\index{unquote-splice} |
| 165 | \index{,}\index{,@} |
| 166 | }{ |
| 167 | In the context of a \mac{backquote}, evaluate \param{value} instead of |
| 168 | using it as-is. \mac{unquote-splice} and \reader{,\texttt{@}} take a |
| 169 | list as their argument, and ``splice'' each element in to |
| 170 | the \mac{backquote} list so that each element of that argument corresponds |
| 171 | to an element of the \mac{backquote} list. |
| 172 | The other two macros insert their argument as a single element in the list. |
| 173 | } |
| 174 | |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 175 | \subsection{Control Flow} |
| 176 | |
| 177 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 178 | (\mac{if} \param{predicate} \param{then} \opt{otherwise}{nil})\index{if} \\ |
| 179 | (\mac{when} \param{predicate} \param{then\more})\index{when} \\ |
| 180 | (\mac{unless} \param{predicate} \param{otherwise\more})\index{unless} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 181 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 182 | First evaluate \param{predicate}. If it is \gls{truthy} evaluate and |
| 183 | return \ret{\param{then}}, otherwise \ret{\param{otherwise}}. If |
| 184 | either is not provided return \ret{\nil}. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 188 | (\mac{progn} \opt{forms\more}{nil})\index{progn} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 189 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 190 | Evaluate \param{forms} from first to last, finally returning |
| 191 | \ret{the last form}. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 192 | } |
| 193 | |
swissChili | a89ee44 | 2021-08-04 20:54:51 -0700 | [diff] [blame] | 194 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 195 | (\mac{and} \param{first} \param{\mighteval{rest}}\more)\index{and} \\ |
| 196 | (\mac{or} \param{first} \param{\mighteval{rest}}\more)\index{or} |
swissChili | a89ee44 | 2021-08-04 20:54:51 -0700 | [diff] [blame] | 197 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 198 | Short circuiting $\land$ and $\lor$, respectively. Return the first |
| 199 | value that is \nil{} or truthy, respectively, or the last value if |
| 200 | all are truthy/\nil{}. |
swissChili | a89ee44 | 2021-08-04 20:54:51 -0700 | [diff] [blame] | 201 | } |
| 202 | |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 203 | \section{Numbers} |
| 204 | |
| 205 | \subsection{Integers} |
| 206 | |
| 207 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 208 | (\func{$+$} \param{a b})\index{+} \\ |
| 209 | (\func{$-$} \param{a b})\index{-} \\ |
| 210 | (\func{$*$} \param{a b})\index{*} \\ |
| 211 | (\func{$/$} \param{a b})\index{/} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 212 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 213 | The \ret{sum, difference, product, or quotient} of \param{a} and |
| 214 | \param{b} as an \type{integer}. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 218 | (\func{=} \param{a b}) |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 219 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 220 | \ret{\T} if \param{a} and \param{b} hold the same \type{integer} |
| 221 | value, \ret{\nil} otherwise. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | \section{Function Manipulation} |
| 225 | |
| 226 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 227 | (\func{funcall} \param{args}\more)\index{funcall} \\ |
| 228 | (\func{apply} \param{function} \param{args})\index{apply} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 229 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 230 | Call the \type{closure} or \type{function-object} \param{function} |
| 231 | with \param{args} and evaluate to \ret{its result}. An error occurs |
| 232 | if \param{args} are not acceptable. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 236 | (\func{recurse} \param{args}\more)\index{recurse} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 237 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 238 | In a lambda definition, call the current lambda with \param{args}. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 242 | (\mac{function} \param{function-name})\index{function} \\ |
| 243 | \reader{\#\textquotesingle}\param{function-name}\index{\#\textquotesingle} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 244 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 245 | Create a \ret{\type{function-object} from an existing function or |
| 246 | macro}. \param{function} must be a symbol literal at compile time. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 250 | (\func{lambda} (\param{args}\more) \param{body}\more)\index{lambda} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 251 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 252 | Create a \ret{lexically-scoped \type{\gls{closure}}} taking |
| 253 | \param{args} and evaluating to \param{body}. |
| 254 | } |
| 255 | |
| 256 | \definition{ |
| 257 | (\func{eval} \param{form})\index{eval} |
| 258 | }{ |
| 259 | Evaluate and return \ret{\param{form}} in the current global |
| 260 | environment. The evaluated form does not use \gls{lexical-scope}. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | \section{Lists} |
| 264 | |
| 265 | \subsection{Creating Lists} |
| 266 | |
| 267 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 268 | (\func{cons} \param{a} \param{b})\index{cons} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 269 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 270 | Join \param{a} and \param{b} into a \ret{\type{cons} pair}. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 274 | (\func{list} \param{values}\more)\index{list} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 275 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 276 | Construct a \ret{\type{cons}-list of \param{values}}. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | \subsection{Deconstructing Lists} |
| 280 | |
| 281 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 282 | (\func{length} \param{list})\index{list} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 283 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 284 | Return the \ret{length of \param{list}} if it is a \type{cons}-list, |
| 285 | \nil{} otherwise. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 289 | (\func{car} \param{pair})\index{car} \\ |
| 290 | (\func{cdr} \param{pair})\index{cdr} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 291 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 292 | Return the \ret{first or second item} of \type{cons} \param{pair}, |
| 293 | respectively. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 297 | (\optlist{ |
| 298 | \func{caar}\\ |
| 299 | \func{cadr}\\ |
| 300 | \func{caddr}\\ |
| 301 | \func{cadar}\\ |
| 302 | \func{caddar} |
| 303 | } \param{val}) |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 304 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 305 | Behave like a combination of \func{car} and \func{cdr} would. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 309 | (\func{elt} \param{list} \param{n})\index{elt} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 310 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 311 | Return the \ret{\param{n}\super{th} element of \param{list}}, |
| 312 | starting from 0, or \ret{\nil} if \param{n} $ \ge $ (\func{length} |
| 313 | \param{list}) or \param{list} is not a \type{cons}-list or \param{n} |
| 314 | is not an \type{integer}. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | \subsection{Operating on Lists} |
| 318 | |
| 319 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 320 | (\func{mapcar} \param{fun} \param{list})\index{mapcar} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 321 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 322 | Apply \param{fun} to each element of \param{list}, returning a |
| 323 | \ret{new \type{cons}-list} containing the results of the respective |
| 324 | applications of \param{fun}. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 328 | (\optlist{\func{remove-if}\\\func{remove-if-not}} |
| 329 | \param{predicate} \param{list})\index{remove-if}\index{remove-if-not} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 330 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 331 | Return a \ret{new \type{cons}-list} of all the items of \param{list} |
| 332 | that either do not or do satisfy \param{predicate}, respectively. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 336 | (\func{reduce} \param{fun} \param{list} \opt{initial-value}{\nil}) |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 337 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 338 | Apply \param{fun} to two arguments at a time, starting with |
| 339 | \param{initial-value} and (\func{car} \param{list}) and continuing |
| 340 | with the result of the previous invocation and the successive |
| 341 | element of \param{list}. Return \ret{the result of the final |
| 342 | invocation}, or \ret{\param{initial-value}} if \param{list} is |
| 343 | empty. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | \section{Input \& Output} |
| 347 | |
| 348 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 349 | (\func{print} \param{value})\index{print} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 350 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 351 | Print \param{value} to standard output. Return \ret{\nil}. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 355 | (\func{read})\index{read} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 356 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 357 | Read and return an \ret{S-expression} from standard input |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | \subsection{Loading Programs} |
| 361 | |
| 362 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 363 | \const{\pluses{current-file}}\index{\pluses{current-file}} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 364 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 365 | The current file being compiled, or \nil{} if not compiling a file. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 369 | (\func{load} \param{lisp-file})\index{load} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 370 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 371 | Load and evaluate \type{string} \param{lisp-file} as a local path |
| 372 | relative to the current file, or the current working directory if |
| 373 | not compiling a file. Return \ret{\nil}. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | \printindex |
| 377 | |
| 378 | \printglossaries |
| 379 | |
| 380 | \end{document} |