% Reference Card for Common Lisp

% Copyright (c) 2001 Gabriel B. Burca. May be freely distributed.
% Created June 20, 2001
% Thanks to Joseph H. Silverman for his Reference Card for C which
% was used as the starting point for this reference card

%**start of header
\newcount\columnsperpage

% This file can be printed with 1, 2, or 3 columns per page (see below).
% [For 2 or 3 columns, you'll need 6 and 8 point fonts.]
% Specify how many you want here.  Nothing else needs to be changed.

\columnsperpage=3

% Copyright (c) 2001 Gabriel B. Burca

% This reference card is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  

% This file is intended to be processed by plain TeX (TeX82).
%
% The final reference card has six columns, three on each side.
% This file can be used to produce it in any of three ways:
% 1 column per page
%    produces six separate pages, each of which needs to be reduced to 80%.
%    This gives the best resolution.
% 2 columns per page
%    produces three already-reduced pages.
%    You will still need to cut and paste.
% 3 columns per page
%    produces two pages which must be printed sideways to make a
%    ready-to-use 8.5 x 11 inch reference card.
%    For this you need a dvi device driver that can print sideways.
% Which mode to use is controlled by setting \columnsperpage above.
%
% Author:
%  Gabriel B. Burca
%  Internet:  gburca-lispRC@ebixio.com
%  (reference card macros due to Stephen Gildea)
%
% Thanks:
%
% History:
%  Version 1.0 - June, 2001, first general distribution

\def\versionnumber{1.0}  % Version of this reference card
\def\year{2001}
\def\month{June}
\def\version{\month\ \year\ v\versionnumber}

\def\shortcopyrightnotice{\vskip .5ex plus 2 fill
  \centerline{\small \copyright\ \year\ Gabriel B. Burca
  Permissions on back.  v\versionnumber}}

\def\copyrightnotice{
\vskip 1ex plus 100 fill\begingroup\small
\centerline{\version. Copyright \copyright\ \year\ Gabriel B. Burca}

Permission is granted to make and distribute copies of
this card provided the copyright notice and this permission notice
are preserved on all copies.

Send comments or corrections to Gabriel B. Burca,
$\langle$gburca-lispRC@ebixio.com$\rangle$

\endgroup}

% make \bye not \outer so that the \def\bye in the \else clause below
% can be scanned without complaint.
\def\bye{\par\vfill\supereject\end}

\newdimen\intercolumnskip
\newbox\columna
\newbox\columnb

\def\ncolumns{\the\columnsperpage}

\message{[\ncolumns\space 
  column\if 1\ncolumns\else s\fi\space per page]}

\def\scaledmag#1{ scaled \magstep #1}

% This multi-way format was designed by Stephen Gildea
% October 1986.
\if 1\ncolumns
  \hsize 4in
  \vsize 10in
  \voffset -.7in
  \font\titlefont=\fontname\tenbf \scaledmag3
  \font\headingfont=\fontname\tenbf \scaledmag2
		\font\headingfonttt=\fontname\tentt \scaledmag2
  \font\smallfont=\fontname\sevenrm
  \font\smallsy=\fontname\sevensy

  \footline{\hss\folio\hss}
  \def\makefootline{\baselineskip10pt\hsize4in\line{\the\footline}}
\else
  \hsize 3.2in
  \vsize 7.95in
  \hoffset -.75in
  \voffset -.745in
  \font\titlefont=cmbx10 \scaledmag2
  \font\headingfont=cmbx10 \scaledmag1
		\font\headingfonttt=cmtt10 \scaledmag1
  \font\smallfont=cmr6
  \font\smallsy=cmsy6
  \font\eightrm=cmr8
  \font\eightbf=cmbx8
  \font\eightit=cmti8
  \font\eighttt=cmtt8
  \font\eightsy=cmsy8
  \font\eightsl=cmsl8
  \font\eighti=cmmi8
  \font\eightex=cmex10 at 8pt
  \textfont0=\eightrm  
  \textfont1=\eighti
  \textfont2=\eightsy
  \textfont3=\eightex
  \def\rm{\fam0 \eightrm}
  \def\bf{\eightbf}
  \def\it{\eightit}
  \def\tt{\eighttt}
  \def\sl{\eightsl}
  \normalbaselineskip=.8\normalbaselineskip
  \normallineskip=.8\normallineskip
  \normallineskiplimit=.8\normallineskiplimit
  \normalbaselines\rm		%make definitions take effect

  \if 2\ncolumns
    \let\maxcolumn=b
    \footline{\hss\rm\folio\hss}
    \def\makefootline{\vskip 2in \hsize=6.86in\line{\the\footline}}
  \else \if 3\ncolumns
    \let\maxcolumn=c
    \nopagenumbers
  \else
    \errhelp{You must set \columnsperpage equal to 1, 2, or 3.}
    \errmessage{Illegal number of columns per page}
  \fi\fi

  \intercolumnskip=.46in
  \def\abc{a}
  \output={%
      % This next line is useful when designing the layout.
      \immediate\write16{Column \folio\abc\space starts with \firstmark}
      \if \maxcolumn\abc \multicolumnformat \global\def\abc{a}
      \else\if a\abc
	\global\setbox\columna\columnbox \global\def\abc{b}
        %% in case we never use \columnb (two-column mode)
        \global\setbox\columnb\hbox to -\intercolumnskip{}
      \else
	\global\setbox\columnb\columnbox \global\def\abc{c}\fi\fi}
  \def\multicolumnformat{\shipout\vbox{\makeheadline
      \hbox{\box\columna\hskip\intercolumnskip
        \box\columnb\hskip\intercolumnskip\columnbox}
      \makefootline}\advancepageno}
  \def\columnbox{\leftline{\pagebody}}

  \def\bye{\par\vfill\supereject
    \if a\abc \else\null\vfill\eject\fi
    \if a\abc \else\null\vfill\eject\fi
    \end}
\fi

% we won't be using math mode much, so redefine some of the characters
% we might want to talk about
%\catcode`\^=12
%\catcode`\_=12
\catcode`\~=12

\chardef\\=`\\
\chardef\{=`\{
\chardef\}=`\}
\chardef\underscore=`\_
\chardef\'="0D % These are upright quote marks


\hyphenation{}

\parindent 0pt
\parskip .85ex plus .35ex minus .5ex

\def\small{\smallfont\textfont2=\smallsy\baselineskip=.8\baselineskip}

\outer\def\newcolumn{\vfill\eject}

\outer\def\title#1{{\titlefont\centerline{#1}}\vskip 1ex plus .5ex}

%\outer\def\section#1{\par\filbreak
%  \vskip .5ex  minus .1ex {\headingfont #1}\mark{#1}%
%  \vskip .3ex  minus .1ex}

\outer\def\section#1{\par
  \vskip .5ex  minus .1ex {\headingfont #1}\mark{#1}%
  \vskip .3ex  minus .1ex}

\outer\def\librarysection#1#2{\par\filbreak
  \vskip .5ex  minus .1ex {\headingfont #1}\quad{\headingfonttt<#2>}\mark{#1}%
  \vskip .3ex  minus .1ex}


\newdimen\keyindent

\def\beginindentedkeys{\keyindent=1em}
\def\endindentedkeys{\keyindent=0em}
\def\begindoubleindentedkeys{\keyindent=2em}
\def\enddoubleindentedkeys{\keyindent=1em}
\endindentedkeys

\def\paralign{\vskip\parskip\halign}

\def\<#1>{$\langle${\rm #1}$\rangle$}

\def\kbd#1{{\tt#1}\null}	%\null so not an abbrev even if period follows

\def\beginexample{\par\vskip1\jot
\hrule width.5\hsize
\vskip1\jot
% \begingroup\parindent=2em
\begingroup
  \obeylines\obeyspaces\parskip0pt\tt}
{\obeyspaces\global\let =\ }
\def\endexample{\endgroup}

\def\Example{\qquad{\sl Example\/}.\enspace\ignorespaces}

\def\key#1#2{\leavevmode\hbox to \hsize{\vtop
  {\hsize=.75\hsize\rightskip=1em
  \hskip\keyindent\relax#1}\kbd{#2}\hfil}}

\newbox\metaxbox
\setbox\metaxbox\hbox{\kbd{M-x }}
\newdimen\metaxwidth
\metaxwidth=\wd\metaxbox

\def\metax#1#2{\leavevmode\hbox to \hsize{\hbox to .75\hsize
  {\hskip\keyindent\relax#1\hfil}%
  \hskip -\metaxwidth minus 1fil
  \kbd{#2}\hfil}}

% bgb
\def\FuncDescr#1#2#3#4{
\metax{#4:}{}
\Function{#1}{#2}{#3}}
\def\Function#1#2#3{\metax{
  \kbd{(#1} \hskip1\jot {\sl #2\/}\kbd{)} \hskip2\jot $\Rightarrow$ #3}{}}


\def\threecol#1#2#3{\hskip\keyindent\relax#1\hfil&\kbd{#2}\quad
  &\kbd{#3}\quad\cr}

% Define Italic Names
\def\makedef#1 {%
\expandafter\edef\csname#1\endcsname{\hbox{\it#1\/}}}
\makedef arg
\makedef chr
\makedef const
\makedef declarations
\makedef dim
\makedef expr
\makedef filename
\makedef fnc
\makedef format
\makedef fp
\makedef label
\makedef lastarg
\makedef member
\makedef mode
\makedef name
\makedef object
\makedef pointer
\makedef statement
\makedef statements
\makedef string
\makedef tag
\makedef text
\makedef type
\makedef value
\makedef var
%added by bgb
\makedef body
\makedef consequent
\makedef element
\makedef form
\makedef keys
\makedef list
\makedef parameter
\makedef place
\makedef result
\makedef test
\makedef then

%**end of header


\title{Common Lisp Reference Card}

% ****************************************
% This goes at the bottom of page 1
\shortcopyrightnotice

\section{Conventions}
\key{one or more}{+}
\key{zero or more}{*}
\key{optional}{[]}
\key{optional with default}{[arg=def]}

\section{Evaluation Control}
\key{prevent evaluation}{quote}
\key{evaluate form}{eval}
\key{apply function to object and list}{apply}
\Function{apply}{function [objects] list}{result}
\key{apply function to objects}{funcall}
\key{fully expands a form}{macroexpand}
\key{return values computed by forms}{values}
\metax{}{multiple-value-bind}

\section{Flow of Control}
\key{list delimeters}{(\quad)}
\key{comment delimeters}{;}
\key{return value from function or loop}{(return \expr)}
\key{}{return-from}
\key{}{prog}
\key{}{prog1}
\key{}{prog2}
\key{}{progn}
\key{}{block}

\metax{{\bf Conditional Flow Control} ({\tt if/when/unless/cond/case})\hidewidth}{}
\beginexample
(if \test \then-\form [\hbox{\it{else-form}\/}])
\vskip1\jot
(when \test \then-\form+)
\vskip1\jot
(unless \test \hbox{\it{else-form+}\/})
\endexample

\beginexample
(cond (\test$_1$ \consequent$_1$+)
      (\test$_2$ \consequent$_2$+)
      \dots
      (\test$_n$ \consequent$_n$+))
\vskip1\jot
(case \hbox{\it{key-form}\/}
  (\hbox{\it{key$_1$}\/} \consequent$_1$+)
  (\hbox{\it{key$_2$}\/} \consequent$_2$+)
  \dots
  (\hbox{\it{key$_n$}\/} \consequent$_n$+))
\endexample

\metax{{\bf Iteration Flow Control} ({\tt dotimes/dolist/do/loop})\hidewidth}{}
\beginexample
(dotimes (\hbox{\it{count}\/} \hbox{\it{upper-bound}\/} \hbox{\it{result}\/})
         \body*)
\endexample

\beginexample
(dolist (\element \list \result)
        \body*)
\endexample

\beginexample
(do ((\parameter$_1$\/ \hbox{\it{initial-value$_1$}\/} \hbox{\it{update-form$_1$}\/})
     (\parameter$_2$\/ \hbox{\it{initial-value$_2$}\/} \hbox{\it{update-form$_2$}\/})
     \dots
     (\parameter$_n$\/ \hbox{\it{initial-value$_n$}\/} \hbox{\it{update-form$_n$}\/})
  (\hbox{\it{termination-test}\/} \hbox{\it{intermediate-forms*}\/} \hbox{\it{result}\/})
  \body*)
\endexample

\beginexample
(loop \body+) ;; (return [\value]) to quit loop
\endexample

\section{Function Definition}
\FuncDescr{defun}{fname (args+) (body)+}{func}{define a function}
\key{define a macro}{defmacro}
\key{}{defsetf}
\key{}{lambda}
\key{}{function}

\section{Numeric Functions}
\metax{sum, difference, product, quotient}{+, -, *, /}
\metax{\Example {\tt(- (* 2 4 3) 5 2) $\Rightarrow$ 17}}{}
\metax{increment, decrement}{1+, 1-}
\FuncDescr{incf/decf}{place [delta]}{new-value}{increment, decrement place}
\key{$\sqrt{x}$}{sqrt x}
\key{$x^y$}{expt x y}
\key{min, max}{min, max}
\metax{\Example {\tt(min -1 2 -3 4 -5 6) $\Rightarrow$ -5}}{}
\key{absolute value}{abs}
\metax{numerator/denominator of rational}{numerator, denominator}
\key{modulus, remainder}{mod, rem}
\key{nearest integer}{round, fround}
\metax{\qquad if between, rounds towards even integer}{}
\metax{truncate towards 0}{truncate, ftruncate}
\metax{truncate towards +$\infty$}{ceiling, fceiling}
\key{truncate towards -$\infty$}{floor, ffloor}
\key{greatest common denominator}{gcd}
\key{least common multiple}{lcm}
\key{sign (-1, 0, or 1)}{signum}
\Function{log}{number [base=$e$]}{logarithm}

\metax{{\bf Trig Functions}}{arguments in radians {\it not}\/ degrees}
\metax{sin, cos, tan}{sin, cos, tan}
\metax{arc sin, cos, tan}{asin, acos, atan}
\metax{hyperbolic}{sinh, cosh, tanh, asinh, acosh, atanh}
\key{3.141592653589793\dots}{pi}


\section{Predicates}
\metax{{\bf General Predicates}}{}
\key{identical objects/symbols}{eq}
\key{eq and same char or number}{eql}
\key{\qquad eql does {\it not}\/ work on lists or strings}{}
\key{structurally similar (isomorphic) objects}{equal}
\key{same components}{equalp}
\key{nil}{null}
\key{object is a cons}{consp}
\metax{\qquad (consp nil) is nil}{}
\key{end of list}{endp}
\key{}{member}

\metax{{\bf Numeric Predicates}}{}
\metax{equal, $\ne$, magnitude/order}{=, /=, <, >, <=, >=}
\key{\Example {\tt(> 7 5 1)} $\Rightarrow$ \tt{t}}{}
\key{parity}{evenp, oddp}
\metax{negative, zero, positive}{minusp, zerop, plusp}

\metax{{\bf String Predicates}}{}
\metax{string/char}{string=, /=, <, >, <=, >=}
\metax{\qquad \tt string-equal, -not-equal}{}
\metax{\qquad \tt string-lessp, -greaterp}{}
\metax{\qquad \tt string-not-greaterp, -not-lessp}{}
\metax{{\bf Character Predicates}}{}
\metax{Use {\bf char} everywhere {\bf string} is used above.}{}

\metax{{\bf Logical Predicates}}{}
\metax{boolean logic}{and, or, not}

\metax{{\bf Type-checking Predicates}}{}
\key{a list}{listp}
\key{a number}{numberp}
\key{an integer}{integerp}
\key{a float}{floatp}
\key{a string}{stringp}
\key{an atom}{atom}
\key{a symbol}{symbolp}
\key{a hash table}{hash-table-p}
\key{of certain type}{typep}

\section{Selection Functions}
\Function{every}{predicate sequences+}{bool}
\Function{some}{predicate sequences+}{bool}
\Function{notevery}{predicate sequences+}{bool}
\Function{notany}{predicate sequences+}{bool}

\section{Assignment}
\key{}{setq}
\key{sequential set place to value}{setf}
\key{parallel set places to values}{psetf}
\key{parallel }{let}
\key{sequential }{let*}
\key{}{set}

\section{Arrays}
\FuncDescr{make-array}{'(dimension+) }{new-array}{create new array}
\FuncDescr{aref}{array-name dimension+}{place}{retrieve array element}
\FuncDescr{setf (aref a1 2 5) 7}{}{7}{set an array element}
\FuncDescr{vector 34 22 30}{}{\#(32 22 30)}{create vector from list of values}

\section{Hash Tables}
\FuncDescr{make-hash-table}{:test \#'equal}{new-ht}{create new hash table}
\FuncDescr{gethash}{'key ht-name}{value}{retrieve a hash value}
\FuncDescr{setf (gethash 'key htbl) 'val}{}{val}{set a hash value}

\section{Structures/Objects}
\FuncDescr{defstruct}{str-t slot1 slot2}{str-t}{define a structure/object type}
\FuncDescr{make-str-t}{:slot1 val \dots}{new-obj}{create an object of type str-t}
\FuncDescr{str-t-slot1}{obj}{val}{retrieve slot1 of obj}
\FuncDescr{setf (str-t-slot1 obj) 'val}{}{val}{set slot1 of obj to val}
\key{obtain type of object}{type-of}

\section{Symbols}
\FuncDescr{get 'symb1 'prop1}{}{value}{retrieve prop1 of symb1}
\FuncDescr{setf (get 'symb1 'prop1) val}{}{val}{set prop1 of symb1 to val} 

\section{Format Codes}
\key{new line}{~\%}
\key{n new lines}{~n\%}
\key{fresh line}{~\&}
\key{page break}{~|}
\key{tab stop}{~T}
\key{n tabs}{~nT}
\key{justification}{~<  ~>}
\key{right justification in field w wide}{~w<  ~>}
\key{character}{~C}
\key{spell out non-printable char}{~:C}
\key{convert to lower case}{~(  ~)}
\key{convert to upper case}{~:@(  ~)}
\key{capitalize each word}{~:(  ~)}
\key{capitalize first word}{~@(  ~)}
\key{decimal integer}{~D}
\key{right justified dec int}{~wD}
\key{decimal integer with +}{~@D}
\key{decimal integer with ,}{~:D}
\key{binary integer}{~B}
\key{octal integer}{~O}
\key{hexadecimal integer}{~X}
\key{base-b integer}{~bR}
\key{spell an integer cardinal (one)}{~R}
\key{spell an integer ordinal (first)}{~:R}
\key{print with Roman numerals}{~@R}
\key{plural with 's'}{~P}
\key{plural with 'y/ies'}{~@P}
\key{reuse previous arg for plural}{~:P  ~:@P}
\key{floating point}{~F}
\key{scientific notation}{~E}
\key{the shorter of ~F or ~E}{~G}
\key{monetary}{~\$}
\key{strings, etc\dots, legibly}{~A}
\key{READably, with escapes}{~S}
\key{~}{~~}

\section{Sequence Operations}
\metax{concatenates sequences as {\it result-type}}{concatenate {\it rt seq+}}
\key{indexes into sequence (0-based)}{elt {\it seq idx}}
\key{}{subseq}
\key{reverses elements in sequence}{reverse}
\key{number of elements in sequence}{length}
\key{number of items occurences in sequence}{count {\it it seq}}
\key{removes occurences of {\it it} in {\it seq}}{remove {\it it seq}}
\metax{substitute {\it new} for {\it old}}{[n]substitute {\it new old seq}}
\key{delete {\it it} from {\it seq}}{delete {\it it seq}}
\metax{}{remove-duplicates}
\metax{}{delete-duplicates}
\key{replace all {\it seq} items with {\it it}}{fill {\it seq it}}
\key{replace items in s1 with s2}{replace {\it s1 s2}}
\metax{\qquad keywords: start1, end1, start2, end2}{}
\key{}{position}
\key{first occurence of item in seq}{find {\it it seq}}
\key{}{search}
\key{}{mismatch}
\key{destructively sort based on predicate}{sort {\it seq pred}}
\key{}{merge}

\section{List Functions}
\key{}{car, first}
\key{}{cdr, rest}
\key{}{cadr}
\metax{}{first, second, ... tenth}
\key{}{last}
\key{}{nth}
\key{}{nthcdr}
\key{}{cons}
\key{}{append}
\key{}{list}
\key{destructive append}{nconc}
\key{}{assoc}
\key{}{subst}

\section{Maping}
\key{}{mapcar}
\key{}{mapc}
\key{}{mapcan}
\key{}{maplist}
\key{}{mapl}
\key{}{mapcon}
\key{}{map}
\key{}{map-into}
\key{}{reduce}

\section{Streams}
\key{}{open}
\key{}{close}
\metax{}{with-open-file}

\section{Documentation}
\key{}{apropos}
\key{}{describe}
\key{}{inspect}
\key{}{documentation}

\section{I/O Functions}
\key{}{read}
\key{}{load}
\key{LISP-readable output}{print}
\key{output w/o delimiters}{princ}
\key{}{pprint}
\key{}{terpri}
\key{}{format}

\section{Compiler Functions}
\key{}{compile}
\key{}{compile-file}
\key{}{defvar}
\key{}{eval-when}

\section{Packages}
\key{}{intern}
\key{}{unintern}
\key{}{export}
\key{}{import}
\key{}{provide}
\key{}{require}
\key{}{in-package}
\key{}{use-package}

\section{Set Functions}
\key{}{adjoin}
\metax{}{[n]intersection}
\metax{}{[n]set-exclusive-or}
\metax{}{[n]set-difference}
\key{}{[n]union}
\key{}{subsetp}

%%%%%%%%%%%%%%%%%%%%%%%%%% END LIBRARIES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% This goes at the bottom of the last page (column 6)
\copyrightnotice
%

\bye

% Local variables:
% compile-command: "tex CRefCard"
% End:
