\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{carol2008} \pdfinfo{ /Title (scheme.pdf) /Creator (Cheatography) /Author (carol2008) /Subject (scheme Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{A3A3A3} \definecolor{LightBackground}{HTML}{F3F3F3} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{scheme Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{carol2008} via \textcolor{DarkBackground}{\uline{cheatography.com/79007/cs/19204/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}carol2008 \\ \uline{cheatography.com/carol2008} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 3rd April, 2019.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{3} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{definition var}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{(define \textless{}var name\textgreater{} \textless{}value\textgreater{})} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{(define pi 3.14)} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{return: pi} \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{definition procedure(func)}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{(define (\textless{}name\textgreater{} \textless{}paras\textgreater{}) \textless{}body\textgreater{})} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{(define (factorial n)\{\{nl\}\}~~~~ (if (= n 0) \{\{nl\}\}~~~~1 \{\{nl\}\}~~~~ (* n (factorial (- n 1)))) )} \tn % Row Count 5 (+ 4) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{return: procedure name} \tn % Row Count 6 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{3.18528 cm} x{1.79172 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{define list}} \tn % Row 0 \SetRowColor{LightBackground} well-formed list (Linked list) & (cons 1 (cons 2 nil)) \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} construct: cons, first: car, rest: cdr & (cons 1 (cons 2 nil)) \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{(list 1 2)} \tn % Row Count 5 (+ 1) % Row 3 \SetRowColor{white} None: nil or'( ) & scm\textgreater{} (null? nil) R:\#t \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{malformed list with . (not linked)} \tn % Row Count 8 (+ 1) % Row 5 \SetRowColor{white} (define x (cons 1 2)) & x \{\{nl\}\}(1 . 2) \tn % Row Count 10 (+ 2) % Row 6 \SetRowColor{LightBackground} create a list & 1. cons 2 list 3'( \tn % Row Count 12 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{1.(cons 1 (cons 2 (cons 3 (cons 4 nil)))) \newline equivalent to : \newline (list 1 2 3 4) \newline \newline 2. (cons 1 2). equivalent to '(1 2). not (list 1 2)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{define lambda expression}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{(lambda (\textless{}formal-parameters\textgreater{}) \textless{}body\textgreater{})} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{((lambda (x y z) (+ x y (square z))) 1 2 3)} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{return 12} \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Same as using define, just no name. In fact, the following expressions are equivalent: \newline (define (plus4 x) (+ x 4)) \newline (define plus4 (lambda (x) (+ x 4))) \newline \newline !!! REMEMBER: in lambda, paras are in ( ).} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.4977 cm} p{0.4977 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{cond expression}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{(cond\{\{nl\}\}~~~~ (\textless{}p1\textgreater{} \textless{}e1\textgreater{}) \{\{nl\}\}~~~~(\textless{}p1\textgreater{} \textless{}e1\textgreater{})\{\{nl\}\}~~~~ ...\{\{nl\}\}~~~~(\textless{}pn\textgreater{} \textless{}en\textgreater{}) \{\{nl\}\}~~~~{[}(else \textless{}else expression\textgreater{}){]})} \tn % Row Count 5 (+ 5) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{\{\{nl\}\}~~~~} \tn % Row Count 6 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{ex: cond}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/carol2008_1554171140_Picture5.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Let}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{lambda: let} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{(let ( ( \textless{}symbol\textgreater{} \textless{}expre1\textgreater{}) \{\{nl\}\}~~~~ ... \{\{nl\}\} ~~~~ ( \textless{}symbol\textgreater{} \textless{}expre2\textgreater{})) \{\{nl\}\} ~~~~\textless{}body\textgreater{})} \tn % Row Count 5 (+ 4) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Ex: we can use the approximation sin(x) = x for small x, and sin(x) = 3sin(x/3)-4(sin(x/3)\textasciicircum{}3) to approach sin(x) for any x} \tn % Row Count 8 (+ 3) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{(define (sin x)\{\{nl\}\} ~~~~(if (\textless{} x 0.000001) \{\{nl\}\}~~~~~~~~ x \{\{nl\}\}~~~~ ~~~~ (let ((recursive-step (sin(/ x 3)))) \{\{nl\}\} ~~~~ ~~~~~~~~(- ( star{\emph{ 3 recursive-step)\{\{nl\}\}~~~~ ~~~~~~~~~~~~ ( star}} 4 (expt recursive-step 3))))))} \tn % Row Count 18 (+ 10) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{nl\}\}~~~~} \tn % Row Count 19 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.58804 cm} x{2.38896 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Lists of Values1}} \tn % Row 0 \SetRowColor{LightBackground} list can contain any data type & Quoting \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} '(1 2 3) & returns the list (1 2 3) \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} '(aa bb cc) & returns the list (aa bb cc) \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} '(1 bb "hello") & returns different data types \tn % Row Count 8 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{1.EVERYTHING in Scheme is a list, even the code. \newline 2. Quoting: to interpret a group of values as a list(instead of as a procedure call), put a single quote in front of them.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.84149 cm} x{3.13551 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{special values}} \tn % Row 0 \SetRowColor{LightBackground} booleans & \#t \#f False false \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} symbol ' & ' : don't eval \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} ? & (even? (quotient 45 2)) R: \#t \tn % Row Count 4 (+ 2) % Row 3 \SetRowColor{white} = only work for numbers & (= \#t \#t) : error \tn % Row Count 6 (+ 2) % Row 4 \SetRowColor{LightBackground} (and) & \#t : if you have a partial and, and what value could you and it to, did not change the original value it is true \tn % Row Count 11 (+ 5) % Row 5 \SetRowColor{white} (or) & \#f \tn % Row Count 12 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{1. ' vs " " \newline (define c 'a) \newline if call c, return a. if no (define a 1), (eval c) will return error \newline (define c "a") \newline if call c, return "a" \newline \newline 2. = only work for numbers \newline (= \#t \#t) : error. \newline (= '(1) '(1)) error \newline \newline 3. but (equal? (= '(1) '(1)) return: true} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{IF Statement}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{if takes in two required arguments and an optional third argument:} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{(if \textless{}predicate\textgreater{} \textless{}if-true\textgreater{} {[}if-false{]})} \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{!! if can do a recursive even at the base case.} \tn % Row Count 4 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{if: python vs scheme \newline 1. scheme eval to a value, python directs the flow \newline 2. scheme: if expression just a single expression for each of \#t and \#f. python: can add more lines \newline 3. scheme: no elif.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{scheme vs python}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/carol2008_1554148735_Picture2.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.93643 cm} x{2.04057 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{List Operation}} \tn % Row 0 \SetRowColor{LightBackground} Define x to be a list of values(bad) & get the first value of x: \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} (define x '(1 2 3)) & (car) \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.4977 cm} p{0.4977 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{construct a list from individual values}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{} \tn % Row Count 0 (+ 0) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{ex: concat 2 lists}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/carol2008_1554167223_Picture3.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{replicate}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/carol2008_1554169796_Picture4.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{replicate(5,3) \newline {[}5,5,5{]} \newline (replicate 5 3) \newline (5 5 5)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.9954 cm} x{3.9816 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{other}} \tn % Row 0 \SetRowColor{LightBackground} and & false finder \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} or & true finder \tn % Row Count 2 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}