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} \\ |
swissChili | fc5c941 | 2021-08-08 19:08:26 -0700 | [diff] [blame] | 116 | \func{closurep} \text{ or } \func{functionp} \\ |
| 117 | \func{integerp} \\ |
| 118 | \func{consp} \\ |
| 119 | \func{symbolp} |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 120 | } \param{value})\index{nilp}\index{not} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 121 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 122 | \ret{\T} if \param{value} is of the specified type, \ret{\nil} |
| 123 | otherwise. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | \subsection{Definitions and Variables} |
| 127 | |
| 128 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 129 | (\mac{defun} \param{name} (\param{args}\more) \param{body}\more)\index{defun} \\ |
| 130 | (\mac{defmacro} \param{name} (\param{args}\more) \param{body}\more)\index{defmacro} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 131 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 132 | Define a function or macro respectively, taking \param{args} |
| 133 | arguments and evaluating \param{body} in turn, finally evaluating to |
| 134 | \ret{the final entry in \param{body}} or \ret{\nil} if \param{body} |
| 135 | is empty. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | \definition{ |
swissChili | fc5c941 | 2021-08-08 19:08:26 -0700 | [diff] [blame] | 139 | (\mac{let1} (\param{variable} \param{form}) \param{body}\more)\index{let1} \\ |
| 140 | (\mac{let} ((\param{variable} \param{form})\more) \param{body}\more)\index{let} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 141 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 142 | First evaluate \param{form}, binding it to \param{variable}. Then |
| 143 | evaluate \param{body}, finally evaluating to \ret{the final entry in |
| 144 | \param{body}} or \ret{\nil} if \param{body} is |
| 145 | empty. \param{variable} is no longer in scope after this form ends. |
swissChili | fc5c941 | 2021-08-08 19:08:26 -0700 | [diff] [blame] | 146 | \mac{let} is similar to \mac{let*} in other lisps, later variables |
| 147 | can reference previous ones. |
| 148 | } |
| 149 | |
| 150 | \definition{ |
| 151 | (\mac{flet1} (\param{name} (\param{args}\more) \param{body}\more)) \\ |
| 152 | (\mac{flet} ((\param{name} (\param{args}\more)\more) \param{body}\more)) |
| 153 | \index{flet}\index{flet1} |
| 154 | }{ |
| 155 | Like \mac{let} and \mac{let1} but creates a lambda. Unlike other |
| 156 | lisps the defined function remains in the variable namespace as a |
| 157 | \type{function-object}. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 161 | \reader{\textquotesingle}\param{value} \\ |
| 162 | (\mac{quote} \param{value})\index{quote} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 163 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 164 | \ret{Return \param{value}} as-is, without evaluating it. |
| 165 | } |
| 166 | |
| 167 | \definition{ |
| 168 | \reader{\`}\param{value} \\ |
| 169 | (\mac{backquote} \param{value})\index{backquote}\index{\`} |
| 170 | }{ |
| 171 | Return \ret{\param{value}} as-is, except for any \mac{unquote} |
| 172 | and \mac{unquote-splice} forms (and their reader-macro equivalents). |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 173 | } |
| 174 | |
swissChili | 3f7f584 | 2021-08-08 17:13:45 -0700 | [diff] [blame] | 175 | \definition{ |
| 176 | \reader{,}\param{value} \\ |
| 177 | (\mac{unquote} \param{value}) \\ |
| 178 | \reader{,\texttt{@}}\param{value} \\ |
| 179 | (\mac{unquote-splice} \param{value}) |
| 180 | \index{unquote}\index{unquote-splice} |
| 181 | \index{,}\index{,@} |
| 182 | }{ |
| 183 | In the context of a \mac{backquote}, evaluate \param{value} instead of |
| 184 | using it as-is. \mac{unquote-splice} and \reader{,\texttt{@}} take a |
| 185 | list as their argument, and ``splice'' each element in to |
| 186 | the \mac{backquote} list so that each element of that argument corresponds |
| 187 | to an element of the \mac{backquote} list. |
| 188 | The other two macros insert their argument as a single element in the list. |
| 189 | } |
| 190 | |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 191 | \subsection{Control Flow} |
| 192 | |
| 193 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 194 | (\mac{if} \param{predicate} \param{then} \opt{otherwise}{nil})\index{if} \\ |
| 195 | (\mac{when} \param{predicate} \param{then\more})\index{when} \\ |
| 196 | (\mac{unless} \param{predicate} \param{otherwise\more})\index{unless} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 197 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 198 | First evaluate \param{predicate}. If it is \gls{truthy} evaluate and |
| 199 | return \ret{\param{then}}, otherwise \ret{\param{otherwise}}. If |
| 200 | either is not provided return \ret{\nil}. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 204 | (\mac{progn} \opt{forms\more}{nil})\index{progn} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 205 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 206 | Evaluate \param{forms} from first to last, finally returning |
| 207 | \ret{the last form}. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 208 | } |
| 209 | |
swissChili | a89ee44 | 2021-08-04 20:54:51 -0700 | [diff] [blame] | 210 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 211 | (\mac{and} \param{first} \param{\mighteval{rest}}\more)\index{and} \\ |
| 212 | (\mac{or} \param{first} \param{\mighteval{rest}}\more)\index{or} |
swissChili | a89ee44 | 2021-08-04 20:54:51 -0700 | [diff] [blame] | 213 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 214 | Short circuiting $\land$ and $\lor$, respectively. Return the first |
| 215 | value that is \nil{} or truthy, respectively, or the last value if |
| 216 | all are truthy/\nil{}. |
swissChili | a89ee44 | 2021-08-04 20:54:51 -0700 | [diff] [blame] | 217 | } |
| 218 | |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 219 | \section{Numbers} |
| 220 | |
| 221 | \subsection{Integers} |
| 222 | |
| 223 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 224 | (\func{$+$} \param{a b})\index{+} \\ |
| 225 | (\func{$-$} \param{a b})\index{-} \\ |
| 226 | (\func{$*$} \param{a b})\index{*} \\ |
| 227 | (\func{$/$} \param{a b})\index{/} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 228 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 229 | The \ret{sum, difference, product, or quotient} of \param{a} and |
| 230 | \param{b} as an \type{integer}. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 234 | (\func{=} \param{a b}) |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 235 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 236 | \ret{\T} if \param{a} and \param{b} hold the same \type{integer} |
| 237 | value, \ret{\nil} otherwise. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | \section{Function Manipulation} |
| 241 | |
| 242 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 243 | (\func{funcall} \param{args}\more)\index{funcall} \\ |
| 244 | (\func{apply} \param{function} \param{args})\index{apply} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 245 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 246 | Call the \type{closure} or \type{function-object} \param{function} |
| 247 | with \param{args} and evaluate to \ret{its result}. An error occurs |
| 248 | if \param{args} are not acceptable. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 252 | (\func{recurse} \param{args}\more)\index{recurse} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 253 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 254 | In a lambda definition, call the current lambda with \param{args}. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 258 | (\mac{function} \param{function-name})\index{function} \\ |
| 259 | \reader{\#\textquotesingle}\param{function-name}\index{\#\textquotesingle} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 260 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 261 | Create a \ret{\type{function-object} from an existing function or |
| 262 | macro}. \param{function} must be a symbol literal at compile time. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 266 | (\func{lambda} (\param{args}\more) \param{body}\more)\index{lambda} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 267 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 268 | Create a \ret{lexically-scoped \type{\gls{closure}}} taking |
| 269 | \param{args} and evaluating to \param{body}. |
| 270 | } |
| 271 | |
| 272 | \definition{ |
| 273 | (\func{eval} \param{form})\index{eval} |
| 274 | }{ |
| 275 | Evaluate and return \ret{\param{form}} in the current global |
| 276 | environment. The evaluated form does not use \gls{lexical-scope}. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | \section{Lists} |
| 280 | |
| 281 | \subsection{Creating Lists} |
| 282 | |
| 283 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 284 | (\func{cons} \param{a} \param{b})\index{cons} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 285 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 286 | Join \param{a} and \param{b} into a \ret{\type{cons} pair}. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 290 | (\func{list} \param{values}\more)\index{list} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 291 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 292 | Construct a \ret{\type{cons}-list of \param{values}}. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | \subsection{Deconstructing Lists} |
| 296 | |
| 297 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 298 | (\func{length} \param{list})\index{list} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 299 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 300 | Return the \ret{length of \param{list}} if it is a \type{cons}-list, |
| 301 | \nil{} otherwise. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 305 | (\func{car} \param{pair})\index{car} \\ |
| 306 | (\func{cdr} \param{pair})\index{cdr} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 307 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 308 | Return the \ret{first or second item} of \type{cons} \param{pair}, |
| 309 | respectively. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 313 | (\optlist{ |
| 314 | \func{caar}\\ |
| 315 | \func{cadr}\\ |
| 316 | \func{caddr}\\ |
| 317 | \func{cadar}\\ |
| 318 | \func{caddar} |
| 319 | } \param{val}) |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 320 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 321 | Behave like a combination of \func{car} and \func{cdr} would. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 325 | (\func{elt} \param{list} \param{n})\index{elt} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 326 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 327 | Return the \ret{\param{n}\super{th} element of \param{list}}, |
| 328 | starting from 0, or \ret{\nil} if \param{n} $ \ge $ (\func{length} |
| 329 | \param{list}) or \param{list} is not a \type{cons}-list or \param{n} |
| 330 | is not an \type{integer}. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | \subsection{Operating on Lists} |
| 334 | |
| 335 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 336 | (\func{mapcar} \param{fun} \param{list})\index{mapcar} |
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 each element of \param{list}, returning a |
| 339 | \ret{new \type{cons}-list} containing the results of the respective |
| 340 | applications of \param{fun}. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 344 | (\optlist{\func{remove-if}\\\func{remove-if-not}} |
| 345 | \param{predicate} \param{list})\index{remove-if}\index{remove-if-not} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 346 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 347 | Return a \ret{new \type{cons}-list} of all the items of \param{list} |
| 348 | that either do not or do satisfy \param{predicate}, respectively. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 352 | (\func{reduce} \param{fun} \param{list} \opt{initial-value}{\nil}) |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 353 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 354 | Apply \param{fun} to two arguments at a time, starting with |
| 355 | \param{initial-value} and (\func{car} \param{list}) and continuing |
| 356 | with the result of the previous invocation and the successive |
| 357 | element of \param{list}. Return \ret{the result of the final |
| 358 | invocation}, or \ret{\param{initial-value}} if \param{list} is |
| 359 | empty. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | \section{Input \& Output} |
| 363 | |
| 364 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 365 | (\func{print} \param{value})\index{print} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 366 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 367 | Print \param{value} to standard output. Return \ret{\nil}. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 371 | (\func{read})\index{read} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 372 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 373 | Read and return an \ret{S-expression} from standard input |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | \subsection{Loading Programs} |
| 377 | |
| 378 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 379 | \const{\pluses{current-file}}\index{\pluses{current-file}} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 380 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 381 | The current file being compiled, or \nil{} if not compiling a file. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | \definition{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 385 | (\func{load} \param{lisp-file})\index{load} |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 386 | }{ |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 387 | Load and evaluate \type{string} \param{lisp-file} as a local path |
| 388 | relative to the current file, or the current working directory if |
| 389 | not compiling a file. Return \ret{\nil}. |
swissChili | 8a4b4ed | 2021-08-03 19:27:32 -0700 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | \printindex |
| 393 | |
| 394 | \printglossaries |
| 395 | |
| 396 | \end{document} |