Permalink
Fetching contributors…
Cannot retrieve contributors at this time
396 lines (336 sloc) 11 KB
% Copyright (C) 2008, 2009, 2010, 2011, 2012, 2014 Bert Burgemeister
%
% Permission is granted to copy, distribute and/or modify this
% document under the terms of the GNU Free Documentation License,
% Version 1.2; with no Invariant Sections, no Front-Cover Texts and
% no Back-Cover Texts. For details see file COPYING.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Conses}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Predicates}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{LIST}{1cm}
\IT{\arrGOO{(\FU*{CONSP} \VAR{ foo})\\
(\FU*{LISTP} \VAR{ foo})}{.}}
{
Return \retval{\T} if \VAR{foo} is of indicated type.
}
\IT{\arrGOO{(\FU*{ENDP} \VAR{ list})\\
(\FU*{NULL} \VAR{ foo})}{.}\qquad\qquad}
{
Return \retval{\T} if \VAR{list}/\VAR{foo} is \NIL.
}
\IT{(\FU*{ATOM} \VAR{foo})\qquad}
{Return \retval{\T} if \VAR{foo} is not a
\kwd{cons}.
}
\IT{(\FU*{TAILP} \VAR{foo} \VAR{list})}
{
Return \retval{\T} if \VAR{foo} is a tail of \VAR{list}.
}
\IT{(\FU*{MEMBER} \VAR{foo} \VAR{list}
\orGOO{\xorGOO{%
\kwd{:test} \VAR{ function}\DF{\kwd{\#'eql}}\\
\kwd{:test-not} \VAR{ function}}{.}\\
\kwd{:key} \VAR{ function}}{\}})}
{
Return \retval{tail of \VAR{list}} starting with
its first element matching \VAR{foo}. Return \retval{\NIL} if
there is no such element.
}
\IT{(\xorGOO{\FU*{MEMBER-IF}\\
\FU*{MEMBER-IF-NOT}}{\}}
\VAR{test} \VAR{list}
\Op{\kwd{:key} \VAR{function}})}
{
Return \retval{tail of \VAR{list}} starting with
its first element satisfying \VAR{test}. Return \retval{\NIL} if
there is no such element.
}
\IT{(\FU*{SUBSETP} \VAR{list-a} \VAR{list-b}
\orGOO{\xorGOO{%
\kwd{:test} \VAR{ function}\DF{\kwd{\#'eql}}\\
\kwd{:test-not} \VAR{ function}}{.}\\
\kwd{:key} \VAR{ function}}{\}})}
{
Return \retval{\T} if \VAR{list-a} is a subset of
\VAR{list-b}.
}
\end{LIST}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Lists}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{LIST}{1cm}
\IT{(\FU*{CONS} \VAR{foo} \VAR{bar})}
{
Return new cons \retval{(\VAR{foo} \kwd {.} \VAR{bar})}.
}
\IT{(\FU*{LIST} \OPn{\VAR{foo}})\qquad\qquad}
{Return \retval{list of \VAR{foo}s}.
}
\IT{(\FU*{LIST\A} \RP{\VAR{foo}})}
{Return \retval{list of \VAR{foo}s}
with last \VAR{foo} becoming cdr of last cons. Return
\retval{\VAR{foo}} if only one \VAR{foo} given.
}
\IT{(\FU*{MAKE-LIST} \VAR{num} \Op{\kwd{:initial-element}
\VAR{foo}\DF{\NIL}})}
{
New \retval{list} with \VAR{num} elements set to \VAR{foo}.
}
\IT{(\FU*{LIST-LENGTH} \VAR{list})}
{\retval{Length} of \VAR{list};
\retval{\NIL} for circular \VAR{list}.
}
\IT{(\FU*{CAR} \VAR{list})\qquad\qquad}
{
\retval{Car of \VAR{list}} or \retval{\NIL} if \VAR{list} is
\NIL. \kwd{SETF}able.
}
\IT{\arrGOO{(\FU*{CDR} \VAR{ list})\qquad\\
(\FU*{REST} \VAR{ list})}{.}}
{
\retval{Cdr of \VAR{list}} or \retval{\NIL} if \VAR{list}
is \NIL. \kwd{SETF}able.
}
\IT{(\FU*{NTHCDR} \VAR{n list})}
{Return \retval{tail of \VAR{list}} after calling \FU{cdr} \VAR{n} times.
}
\IT{(\Goo{\FU*{FIRST}\XOR\FU*{SECOND}\XOR\FU*{THIRD}\XOR\FU*{FOURTH}\XOR\FU*{FIFTH}\XOR\FU*{SIXTH}\XOR\dots\XOR\FU*{NINTH}\XOR\FU*{TENTH}}
\VAR{list})}
{
\index{SEVENTH}%
\index{EIGHTH}%
Return \retval{nth element of \VAR{list}} if any,
or \retval{\NIL} otherwise. \kwd{SETF}able.
}
\IT{(\FU*{NTH} \VAR{n list})}
{
Zero-indexed \retval{\VAR{n}th element} of \VAR{list}. \kwd{setf}able.
}
\IT{(\FU{C}\VAR{X}\kwd{R} \VAR{list})}
{
\index{CAAR}%
\index{CADR}%
\index{CDAR}%
\index{CDDR}%
With \VAR{X} being one to four
\kwd{a}s and \kwd{d}s representing \FU{CAR}s and \FU{CDR}s, e.g.
(\FU{CADR} \VAR{bar}) is equivalent to (\FU{CAR} (\FU{CDR}
\VAR{bar})).
\kwd{SETF}able.
}
\IT{(\FU*{LAST} \VAR{list} \Op{\VAR{num}\DF{\LIT{1}}})}
{
Return list of \retval{last \VAR{num}
conses} of \VAR{list}.
}
\IT{(\xorGOO{\FU*{BUTLAST } \VAR{list}\\
\FU*{NBUTLAST } \DES{\VAR{list}}}{\}}
\Op{\VAR{num}\DF{\LIT{1}}})}
{
\retval{\VAR{list}} excluding last \VAR{num}
conses.
}
\IT{(\xorGOO{\FU*{RPLACA}\\
\FU*{RPLACD}}{\}} \DES{\VAR{cons}} \VAR{object})}
{
Replace car, or cdr, respectively, of \retval{\VAR{cons}} with \VAR{object}.
}
\IT{(\FU*{LDIFF} \VAR{list} \VAR{foo})}
{
If \VAR{foo} is a tail of \VAR{list}, return \retval{preceding
part of \VAR{list}}. Otherwise return \retval{\VAR{list}}.
}
\IT{(\FU*{ADJOIN} \VAR{foo} \VAR{list}
\orGOO{\xorGOO{%
\kwd{:test} \VAR{ function}\DF{\kwd{\#'eql}}\\
\kwd{:test-not} \VAR{ function}}{.}\\
\kwd{:key} \VAR{ function}}{\}})}
{Return \retval{\VAR{list}} if \VAR{foo} is
already member of \VAR{list}. If not, return \retval{(\FU{CONS}
\VAR{foo} \VAR{list})}.
}
\IT{(\MC*{POP} \DES{\VAR{place}})}
{
Set \VAR{place} to (\FU{CDR} \VAR{place}), return
\retval{(\FU{CAR} \VAR{place})}.
}
\IT{(\MC*{PUSH} \VAR{foo} \DES{\VAR{place}})}
{
Set \VAR{place} to \retval{(\FU{cons} \VAR{foo} \VAR{place})}.
}
\IT{(\MC*{PUSHNEW} \VAR{foo} \DES{\VAR{place}}
\orGOO{\xorGOO{%
\kwd{:test} \VAR{ function}\DF{\kwd{\#'eql}}\\
\kwd{:test-not} \VAR{ function}}{.}\\
\kwd{:key} \VAR{ function}}{\}})}
{
Set \VAR{place} to \retval{(\FU{adjoin} \VAR{foo} \VAR{place})}.
}
\IT{\arrGOO{(\FU*{APPEND } \Op{\OPn{\VAR{proper-list}}
\VAR{ foo}\DF{\NIL}})\\
(\FU*{NCONC } \Op{\OPn{\DES{\VAR{non-circular-list}}}
\VAR{ foo}\DF{\NIL}})}{.}}
{
Return \retval{concatenated list} or, with only one argument,
\retval{\VAR{foo}}. \VAR{foo} can be of any type.
}
\IT{\arrGOO{(\FU*{REVAPPEND} \VAR{ list} \VAR{ foo})\\
(\FU*{NRECONC }
\DES{\VAR{list}} \VAR{ foo})}{.}}
{
Return \retval{concatenated list} after reversing order in
\VAR{list}.
}
\IT{(\xorGOO{\FU*{MAPCAR}\\
\FU*{MAPLIST}}{\}} \VAR{function} \RP{\VAR{list}})}
{
Return \retval{list of return values} of \VAR{function}
successively invoked with corresponding arguments, either cars or
cdrs, respectively, from each \VAR{list}.
}
\IT{(\xorGOO{\FU*{MAPCAN}\\
\FU*{MAPCON}}{\}} \VAR{function} \RP{\VAR{\DES{list}}})}
% Example of list argument being modified:
% (let ((list '((1 2) (3 4))))
% (mapcan #'identity list)
% list)
{
Return list of \retval{concatenated return values} of
\VAR{function} successively invoked with corresponding arguments,
either cars or cdrs, respectively, from each
\VAR{list}. \VAR{function} should return a list.
}
\IT{(\xorGOO{\FU*{MAPC}\\
\FU*{MAPL}}{\}} \VAR{function} \RP{\VAR{list}})}
{
Return \retval{first \VAR{list}} after successively applying
\VAR{function} to corresponding arguments, either cars or cdrs,
respectively, from each \VAR{list}. \VAR{function} should have
some side effects.
}
\IT{(\FU*{COPY-LIST} \VAR{list})}
{
Return \retval{copy} of \VAR{list} with shared elements.
}
\end{LIST}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Association Lists}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\label{section:Association Lists}
\begin{LIST}{1cm}
\IT{(\FU*{PAIRLIS} \VAR{keys} \VAR{values} \Op{\VAR{alist}\DF{\NIL}})}
{
Prepend to \retval{\VAR{alist}} an association list made from
lists \VAR{keys} and \VAR{values}.
}
\IT{(\FU*{ACONS} \VAR{key} \VAR{value} \VAR{alist})}
{
Return \retval{\VAR{alist}} with a (\VAR{key} \kwd{.} \VAR{value})
pair added.
}
\IT{\arrGOO{(\xorGOO{\FU*{ASSOC}\\
\FU*{RASSOC}}{\}}
\VAR{ foo} \VAR{ alist }
\orGOO{\xorGOO{%
\kwd{:test} \VAR{ test}\DF{\kwd{\#'eql}}\\
\kwd{:test-not} \VAR{ test}}{.}\\
\kwd{:key} \VAR{ function}
}{\}})\\
(\xorGOO{\FU*{ASSOC-IF}\Op{\kwd{-NOT}}\\
\FU*{RASSOC-IF}\Op{\kwd{-NOT}}}{\}} \VAR{ test} \VAR{ alist }
\Op{\kwd{:key} \VAR{ function}})}{.}}
{\index{ASSOC-IF-NOT}\index{RASSOC-IF-NOT}%
First \retval{cons} whose car, or cdr, respectively, satisfies
\VAR{test}.
}
\IT{(\FU*{COPY-ALIST} \VAR{alist})}
{
Return \retval{copy} of \VAR{alist}.
}
\end{LIST}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Trees}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{LIST}{1cm}
\IT{(\FU*{TREE-EQUAL} \VAR{foo} \VAR{bar}
\xorGOO{\kwd{:test} \VAR{ test}\DF{\kwd{\#'eql}}\\
\kwd{:test-not} \VAR{ test}}{\}})}
{
Return \retval{\T} if trees \VAR{foo} and \VAR{bar} have same
shape and leaves satisfying \VAR{test}.
}
\IT{(\xorGOO{\FU*{SUBST} \VAR{ new} \VAR{ old } \VAR{tree}\\
\FU*{NSUBST} \VAR{ new} \VAR{ old } \DES{\VAR{tree}}}{\}}
\orGOO{\xorGOO{%
\kwd{:test} \VAR{ function}\DF{\kwd{\#'eql}}\\
\kwd{:test-not} \VAR{ function}}{.}\\
\kwd{:key} \VAR{ function}%
}{\}})}
{
Make \retval{copy of \VAR{tree}} with each subtree or leaf
matching \VAR{old} replaced by \VAR{new}.
}
\IT{(\xorGOO{\FU{SUBST-IF\Op{-NOT}} \VAR{ new} \VAR{ test } \VAR{tree}\\
\FU{NSUBST-IF\Op{-NOT}} \VAR{ new} \VAR{ test } \DES{\VAR{tree}}}{\}}
\Op{\kwd{:key} \VAR{function}})}
{
\index{SUBST-IF}%
\index{SUBST-IF-NOT}%
\index{NSUBST-IF}%
\index{NSUBST-IF-NOT}%
Make \retval{copy of \VAR{tree}} with each subtree or leaf
satisfying \VAR{test} replaced by \VAR{new}.
}
\IT{(\xorGOO{\FU*{SUBLIS} \VAR{ association-list } \VAR{tree} \\
\FU*{NSUBLIS} \VAR{ association-list } \DES{\VAR{tree}} }{\}}
\orGOO{\xorGOO{%
\kwd{:test} \VAR{ function}\DF{\kwd{\#'eql}}\\
\kwd{:test-not} \VAR{ function}}{.}\\
\kwd{:key} \VAR{ function}%
}{\}})}
{
Make \retval{copy of \VAR{tree}} with each subtree or leaf matching
a key in \VAR{association-list} replaced by that key's value.
}
\IT{(\FU*{COPY-TREE} \VAR{tree})}
{
\retval{Copy of \VAR{tree}} with same shape and leaves.
}
\end{LIST}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Sets}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{LIST}{1cm}
\IT{(\xorGOO{%
\arrGOO{%
\FU*{INTERSECTION}\\
\FU*{SET-DIFFERENCE}\\
\FU*{UNION}\\
\FU*{SET-EXCLUSIVE-OR}%
}{\}} \VAR{ a} \VAR{ b}\\
\arrGOO{%
\FU*{NINTERSECTION}\\
\FU*{NSET-DIFFERENCE}%
}{\}} \text{ }\DES{\VAR{a}}\text{ } \VAR{b}\\
\arrGOO{%
\FU*{NUNION}\\
\FU*{NSET-EXCLUSIVE-OR}%
}{\}} \text{ }\DES{\VAR{a}}\text{ } \DES{\VAR{b}}\text{ }
}{\}}
\orGOO{\xorGOO{%
\kwd{:test} \VAR{ function}\DF{\kwd{\#'eql}}\\
\kwd{:test-not} \VAR{ function}}{.}\\
\kwd{:key} \VAR{ function}}{\}})}
{
Return \retval{$a\cap b$}, \retval{$a\setminus b$}, \retval{$a\cup b$}, or
\retval{$a\,\triangle\, b$}, respectively, of lists \VAR{a} and \VAR{b}.
}
\end{LIST}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: "clqr"
%%% End: