Add CT331 Programming Paradigms
This commit is contained in:
Binary file not shown.
@ -0,0 +1,608 @@
|
||||
%! TeX program = lualatex
|
||||
\documentclass[a4paper,11pt]{article}
|
||||
% packages
|
||||
\usepackage{fontspec}
|
||||
\setmainfont{EB Garamond}
|
||||
% for tironian et fallback
|
||||
% % \directlua{luaotfload.add_fallback
|
||||
% % ("emojifallback",
|
||||
% % {"Noto Serif:mode=harf"}
|
||||
% % )}
|
||||
% % \setmainfont{EB Garamond}[RawFeature={fallback=emojifallback}]
|
||||
|
||||
\setmonofont[Scale=MatchLowercase]{Deja Vu Sans Mono}
|
||||
\usepackage[a4paper,left=2cm,right=2cm,top=\dimexpr15mm+1.5\baselineskip,bottom=2cm]{geometry}
|
||||
\setlength{\parindent}{0pt}
|
||||
|
||||
\usepackage{fancyhdr} % Headers and footers
|
||||
\fancyhead[R]{\normalfont \leftmark}
|
||||
\fancyhead[L]{}
|
||||
\pagestyle{fancy}
|
||||
|
||||
\usepackage{multicol}
|
||||
\usepackage{microtype} % Slightly tweak font spacing for aesthetics
|
||||
\usepackage[english]{babel} % Language hyphenation and typographical rules
|
||||
\usepackage[final, colorlinks = true, urlcolor = blue, linkcolor = black]{hyperref}
|
||||
\usepackage{changepage} % adjust margins on the fly
|
||||
|
||||
\usepackage{minted}
|
||||
\usemintedstyle{algol_nu}
|
||||
\usepackage{xcolor}
|
||||
|
||||
\usepackage{pgfplots}
|
||||
\pgfplotsset{width=\textwidth,compat=1.9}
|
||||
|
||||
\usepackage{caption}
|
||||
\newenvironment{code}{\captionsetup{type=listing}}{}
|
||||
|
||||
\usepackage[yyyymmdd]{datetime}
|
||||
\renewcommand{\dateseparator}{-}
|
||||
|
||||
\usepackage{titlesec}
|
||||
|
||||
\begin{document}
|
||||
\begin{titlepage}
|
||||
\begin{center}
|
||||
\hrule
|
||||
\vspace*{0.6cm}
|
||||
\huge \textbf{CT331}
|
||||
\vspace*{0.6cm}
|
||||
\hrule
|
||||
\LARGE
|
||||
\vspace{0.5cm}
|
||||
PROGRAMMING PARADIGMS
|
||||
\vspace{0.5cm}
|
||||
\hrule
|
||||
|
||||
\vfill
|
||||
\includegraphics[width=0.8\textwidth]{images/lambda.png}
|
||||
\vfill
|
||||
|
||||
\Large
|
||||
\vspace{0.5cm}
|
||||
\hrule
|
||||
\vspace{0.5cm}
|
||||
\textbf{Andreas Ó hAoḋa}
|
||||
% \vspace{0.5cm}
|
||||
% \hrule
|
||||
% \vspace{0.5cm}
|
||||
|
||||
\normalsize
|
||||
University of Galway
|
||||
|
||||
\today
|
||||
|
||||
\vspace{0.5cm}
|
||||
\hrule
|
||||
\end{center}
|
||||
\end{titlepage}
|
||||
|
||||
\pagenumbering{roman}
|
||||
\newpage
|
||||
\tableofcontents
|
||||
\newpage
|
||||
\setcounter{page}{1}
|
||||
\pagenumbering{arabic}
|
||||
|
||||
\section{Introduction}
|
||||
\subsection{Lecturer Contact Information}
|
||||
\begin{itemize}
|
||||
\item Finlay Smith, School of Computer Science.
|
||||
\item \href{mailto://finlay.smith@universityofgalway.ie}{\texttt{finlay.smith@universityofgalway.ie}}
|
||||
\end{itemize}
|
||||
|
||||
\subsection{Syllabus}
|
||||
This module introduces three different programming paradigms: Procedural, Functional \& Logical.
|
||||
This will involve 3 programming languages: C (mostly function pointers - knowledge of C is assumed), LISP
|
||||
(a functional language) and Prolog (a logical language).
|
||||
Both LISP and Prolog will both be introduced but neither will be fully covered in this module.
|
||||
There are no books required or recommended for this course.
|
||||
|
||||
\subsubsection{Marking}
|
||||
30\% of the marks for this module will be for the three assignments (one for each paradigm).
|
||||
The remaining 70\% of the marks will be for the written exam.
|
||||
|
||||
\subsection{Programming Paradigms}
|
||||
A \textbf{paradigm} is a typical example or pattern of something; a pattern or model.
|
||||
A \textbf{programming paradigm} is a pattern or model of programming.
|
||||
Various types of programming languages are better suited to solving particular problems.
|
||||
Programming language implementations differ on semantics \& syntax:
|
||||
\begin{itemize}
|
||||
\item \textbf{Syntax} refers to the rules of the language; it allows us to form valid expressions \& statements.
|
||||
\item \textbf{Semantics} refers to the meaning of those expressions \& statements.
|
||||
\end{itemize}
|
||||
|
||||
Programming languages can be classified according to the features that they have with respect to both the conceptual \& implementation
|
||||
level.
|
||||
An alternative definition for a \textbf{programming paradigm} is a collection of abstract features that categorise a group of
|
||||
languages.
|
||||
|
||||
``\textit{The popularity of a paradigm is due to one community deciding which problems are important to solve and then supporting the
|
||||
most promising paradigm for attacking these problems.}'' -- Thomas Kuhn.
|
||||
|
||||
\subsection{Influences on Paradigms}
|
||||
\begin{itemize}
|
||||
\item Computer Capabilities.
|
||||
\item Applications.
|
||||
\item Programming Methods: Language designs have evolved to reflect changing understanding of good methods for writing
|
||||
large \& complex programs.
|
||||
\item Implementation Methods: Early compilers to optimised compilers; structured engineering to software engineering; data
|
||||
abstraction to OO.
|
||||
\item Theoretical Studies: Formal maths methods have deepened our understanding of strengths \& weaknesses of language
|
||||
features and thus influenced the choice \& inclusion of those features.
|
||||
\item Standardisation (has proved to be a strong conservative influence on the evolution of programming language design).
|
||||
\end{itemize}
|
||||
|
||||
\subsection{Why Learn Different Paradigms?}
|
||||
\begin{itemize}
|
||||
\item Different paradigms make different trade-offs; What's tricky in one paradigm is ``baked in'' in another.
|
||||
\item Changing paradigms forces you to ``change gears''.
|
||||
\item It will prepare you for learning languages that you've never heard of or that may not exist yet.
|
||||
\item Helps you to decide what the best tool for the job is.
|
||||
\item Helps you to understand languages at a deeper level.
|
||||
\end{itemize}
|
||||
|
||||
\subsubsection{Why Learn Functional Programming?}
|
||||
\begin{itemize}
|
||||
\item It's one of the oldest paradigm (Lisp: 1958, still widely used today).
|
||||
\item Heavily based on mathematical concepts (proofs, lambda calculations).
|
||||
\item Elegant solutions (recursion).
|
||||
\item Other paradigms can be interpreted in terms of functional programming.
|
||||
\end{itemize}
|
||||
|
||||
\subsubsection{Why Learn Logical Programming?}
|
||||
\begin{itemize}
|
||||
\item Long history.
|
||||
\item ALlows implementation of things that are difficult in other paradigms.
|
||||
\item \emph{Very} different
|
||||
\item Helps to conceptualise logical problems.
|
||||
\end{itemize}
|
||||
|
||||
\subsubsection{Why Learn Imperative Programming?}
|
||||
\begin{itemize}
|
||||
\item The oldest paradigm -- goes back as far as punch cards \& magnetic loops.
|
||||
\item Much closer representation of how the machine actually works, i.e. ``closer to the metal''.
|
||||
\item Can help to recognise optimisation issues / computational bottlenecks.
|
||||
\item Contextualises many other systems (UNIX, Linux, etc.).
|
||||
\end{itemize}
|
||||
|
||||
\subsubsection{Why Learn Object-Oriented Programming?}
|
||||
\begin{itemize}
|
||||
\item Tries to represent the real world.
|
||||
\item Abstraction \& inheritance.
|
||||
\item Object-Oriented is everywhere.
|
||||
\end{itemize}
|
||||
|
||||
\section{Overview of Object-Oriented Programming}
|
||||
Object-Oriented languages include:
|
||||
\begin{multicols}{2}
|
||||
\begin{itemize}
|
||||
\item Java.
|
||||
\item C\#.
|
||||
\item VB.NET.
|
||||
\item Scala.
|
||||
\item JavaScript.
|
||||
\item Python.
|
||||
\item PHP.
|
||||
\item Smalltalk.
|
||||
\item Ruby.
|
||||
\end{itemize}
|
||||
\end{multicols}
|
||||
|
||||
\subsection{Fundamentals of Object-Oriented Programming}
|
||||
\begin{itemize}
|
||||
\item Everything is an object.
|
||||
\item Computation is performed by message-passing.
|
||||
\item Every \textbf{object} is an \textbf{instance} of a \textbf{class} which is a grouping of similar objects.
|
||||
\item \textbf{Inheritance} describes the relationships between classes.
|
||||
\end{itemize}
|
||||
|
||||
Object-Oriented Programming focuses on the objects that the program represents and allows them to exhibit ``behaviour''.
|
||||
|
||||
\subsection{Four Major Principles of OOP}
|
||||
\subsubsection{Encapsulation}
|
||||
Data is hidden as if \textbf{encapsulated} within the object.
|
||||
Direct access to the data is restricted, instead we use methods to get, set, \& manipulate data.
|
||||
Manipulation of data is hidden.
|
||||
The object caller doesn't need to know what's actually going on behind the scenes.
|
||||
We can be (fairly) sure that nobody else is fiddling with our data.
|
||||
|
||||
\subsubsection{Abstraction}
|
||||
Functionality can be defined without actually being implemented.
|
||||
High-level interfaces provide method types/names without implementation.
|
||||
This allows case-specific implementation, allows one person to define the functionality \& another to implement, and
|
||||
allows the representation to be changed without affecting ``public'' view of the class.
|
||||
This is helpful when designing large systems.
|
||||
|
||||
\subsubsection{Inheritance}
|
||||
Classes can \textbf{inherit} functionality without re-implementing.
|
||||
This prevents the duplication of code.
|
||||
This is also helpful when designing large systems; it encourages a well-structured codebase.
|
||||
|
||||
\subsubsection{Polymorphism}
|
||||
Objects of one class can be treated like objects of other classes.
|
||||
|
||||
\section{Imperative \& Procedural Programming}
|
||||
\subsection{Imperative Programming}
|
||||
\textbf{Imperative programming} involves telling the computer to perform a set of actions, one after the other.
|
||||
Most programming languages have imperative aspects.
|
||||
Imperative programming consists of a list of instructions, \verb|GOTO| statements, and little or no structure.
|
||||
E.g., Assembly.
|
||||
|
||||
\subsection{Procedural Progamming}
|
||||
\textbf{Procedural progamming} splits actions into \textbf{procedures} or tasks.
|
||||
Procedures can be made up of other procedures (composition, recursion).
|
||||
The code is structured, uses ``functions'' or procedures, encourages code re-use, and encourages encapsulation \&
|
||||
composition.
|
||||
Note that procedural functions are not to be confused with Functional Programming.
|
||||
|
||||
\subsubsection{Structured Programming}
|
||||
Examples of structured programming languages include basically everything except Assembly.
|
||||
\begin{itemize}
|
||||
\item Code is structured.
|
||||
\item \verb|while|, \verb|for|, \verb|if|, \verb|else,| \verb|switch|, \verb|class|, \verb|function|, etc.
|
||||
\item Less emphasis on \verb|GOTO| statements.
|
||||
\item Creating a structure to manage instructions.
|
||||
\item Allows more complex programs to be built.
|
||||
\item Easier to understand.
|
||||
\item Helps to avoid \verb|GOTO| bugs \& spaghetti code.
|
||||
\end{itemize}
|
||||
|
||||
\subsection{The C Programming Language}
|
||||
\textbf{C} is a procedural, imperative, structured ``systems language''.
|
||||
It came into being around 1969-1973 in parallel with the development of the UNIX operating system.
|
||||
Basic Compiled Programming Language (BCPL) \rightarrow B \rightarrow C...
|
||||
C has had an ANSI standard since the 1980s.
|
||||
Now one of the most popular \& powerful languages in use today.
|
||||
\begin{code}
|
||||
\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{c}
|
||||
// header inclusion: functionally defined in stdio.h is added into the program by the compiler, specifically the Linker step of the compiler
|
||||
// "stdio" is short for "Standard Input / Output"
|
||||
#include <stdio.h>
|
||||
|
||||
// function prototype: tells the compiler that the function exists before it has been implemented
|
||||
// allows the compiler to handle recursion, or functions calling each other
|
||||
void sayHello();
|
||||
|
||||
// function definition: implements the function
|
||||
// note: data type, arguments, return
|
||||
void sayHello() {
|
||||
// calling a function: printf takes a char* argument
|
||||
printf("Hello World!\n");
|
||||
}
|
||||
|
||||
// main function: the entry point to the progam
|
||||
// returns int
|
||||
// takes two arguments: argc (the number of command-line arguments) & argv (an array of the arguments)
|
||||
int main(int argc, char* argv[]) {
|
||||
// calling a function: sayhello takes no argument. nothing is returned
|
||||
sayHello();
|
||||
return 0;
|
||||
}
|
||||
\end{minted}
|
||||
\caption{Example C Program: \texttt{helloWorld.c}}
|
||||
\end{code}
|
||||
|
||||
\begin{code}
|
||||
\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{c}
|
||||
#include <stdio.h>
|
||||
|
||||
int add(int a, int b);
|
||||
|
||||
int add(int a, int b) {
|
||||
return a+b;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
printf("Let's add some numbers...\n");
|
||||
int first = 8;
|
||||
int second = 4;
|
||||
printf("The first number is %d\n", first);
|
||||
printf("The second number is %d\n", second);
|
||||
|
||||
// "add" is a function that returns an int
|
||||
// the returned int is stored in the "result" variable - they must have the same data type
|
||||
int result = add(first, second);
|
||||
|
||||
|
||||
// "%d" is for ints - strictly decimal ints
|
||||
// "%i" is any int including octal and hexadecimal
|
||||
printf("When we add them together we get: %d\n", result);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
\end{minted}
|
||||
\caption{Example C Program: \texttt{addNumbers.c}}
|
||||
\end{code}
|
||||
|
||||
\subsubsection{Pointers}
|
||||
\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{c}
|
||||
int* p; // variable p is a pointer to an integer value
|
||||
int i; // integer value
|
||||
\end{minted}
|
||||
|
||||
You can \textbf{dereference} a pointer into a value with \verb|*|.
|
||||
\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{c}
|
||||
// ineger i2 is assigned the integer value that the pointer p is pointing to
|
||||
int i2 = *p;
|
||||
\end{minted}
|
||||
|
||||
You can get a pointer to a value with \verb|&|.
|
||||
\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{c}
|
||||
// pointer p2 points to the address of integer i
|
||||
int* p2 = &i;
|
||||
\end{minted}
|
||||
|
||||
A function effectively breaking the convention that arguments are not changed in a function is a \textbf{side effect}.
|
||||
This is done by passing addresses.
|
||||
\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{c}
|
||||
#include<stdio.h>
|
||||
|
||||
void swap(int* x, int* y) {
|
||||
int temp = *x;
|
||||
*x = *y;
|
||||
*y = temp;
|
||||
}
|
||||
|
||||
int main(int argc, char* arv[]) {
|
||||
int a = 8;
|
||||
int b = 4;
|
||||
swap(&a, &b); // this should make a=4 & b=8
|
||||
}
|
||||
\end{minted}
|
||||
|
||||
\subsubsection{Arrays \& Pointers}
|
||||
\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{c}
|
||||
int intArr[5]; // an integer array of size 5
|
||||
// intArr is a pointer to the 0th element of the array - the same as &intArr[0]
|
||||
|
||||
intArr[2] = 3; // same as *(intArr+2) = 3;
|
||||
// (intArr + 2) is of type (int*) while intArr[2] is of type int
|
||||
// in the latter case, the pointer is dereferenced
|
||||
// (intArr + 2) is the same as (&(intArr[2]))
|
||||
// note that the + operator here is not simple addition - it moves the pointer by the size of the type
|
||||
\end{minted}
|
||||
|
||||
\subsubsection{Generic Swap function?}
|
||||
What about a swap function that works on any data type?
|
||||
\begin{code}
|
||||
\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{c}
|
||||
void swap(void* x, void* y) {
|
||||
void temp = *x; // won't work!
|
||||
// we don't know what size data *x points to, so void temp can't work
|
||||
// it is impossible to have a variable of type void for this reason
|
||||
// but we can have a pointer of type void*
|
||||
|
||||
*x = *y;
|
||||
*y = temp;
|
||||
}
|
||||
\end{minted}
|
||||
\caption{(Non-functional) Attempt at a Generic \texttt{swap} Function}
|
||||
\end{code}
|
||||
\mintinline{c}{void*} is a specific pointer type which points to some location in memory.
|
||||
It has no specific type and therefore no specific size.
|
||||
\\\\
|
||||
\mintinline{c}{sizeof(<type>)} returns the size in bytes of the object representation of \verb|<type>|.
|
||||
\verb|sizeof()| is built-in to the C langauge.
|
||||
\\\\
|
||||
\mintinline{c}{void* memcpy(void* to, const void* from, size_t size)}.
|
||||
The \verb|memcpy()| function copies \verb|size| number of bytes from the object beginning at location \verb|from| into
|
||||
the object beginning at location \verb|to|.
|
||||
The value returned by \verb|memcpy()| is the value of \verb|to|.
|
||||
The \verb|memcpy()| function is defined in \verb|string.h|.
|
||||
|
||||
\begin{code}
|
||||
\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{c}
|
||||
#include <string.h>
|
||||
|
||||
void generic_swap(void* vp1, void* vp2, int size) {
|
||||
char temp_buff[size]; // need malloc?
|
||||
memcpy(temp_buff, vp1, size);
|
||||
memcpy(vp1, vp2, size);
|
||||
memcpy(vp2, temp_buff, size);
|
||||
}
|
||||
\end{minted}
|
||||
\caption{Generic Swap Function}
|
||||
\end{code}
|
||||
|
||||
\subsection{Stacks vs Heaps}
|
||||
A \textbf{stack} is a LIFO data structure of limited size \& limited access.
|
||||
It supports only two operations: PUSH \& POP.
|
||||
Stacks are very fast.
|
||||
The limited size of stacks can result in stack overflow, and you cannot free memory in a stack except by POPping.
|
||||
To continue the \verb|swap()| function from above:
|
||||
\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{c}
|
||||
// first, a, b, & c are pushed onto the stack
|
||||
char a = 'a';
|
||||
int b = 100;
|
||||
int c = 50;
|
||||
|
||||
// when swap() is called, x, y, & temp are pushed onto the stack
|
||||
void swap(int* x, int* y) {
|
||||
int temp = *x;
|
||||
*x = *y;
|
||||
*y = temp;
|
||||
|
||||
// when swap returns, x, y, & temp are popped from the stack and \textbf{their memory is no longer in use}
|
||||
}
|
||||
|
||||
swap(b, c);
|
||||
\end{minted}
|
||||
|
||||
But what if we want to keep track of \verb|temp| and use it later?
|
||||
\\\\
|
||||
A \textbf{heap} is an unordered data structure of (theoretically) unlimited size and global access.
|
||||
The heap operations are allocate \& free.
|
||||
Heaps are slower than stacks.
|
||||
Heaps are also harder to manage than stacks as they can get memory leaks.
|
||||
\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{c}
|
||||
// first, b & c are pushed onto the stack
|
||||
int b = 100;
|
||||
int c = 50;
|
||||
|
||||
// when swap() is called, x, y, & temp are pushed onto the stack
|
||||
void* swap(int* x, int* y) {
|
||||
int temp = *x;
|
||||
|
||||
// we allocate space in memory to perm using malloc
|
||||
int* perm = malloc(int);
|
||||
perm = &temp;
|
||||
x = y;
|
||||
y = *perm;
|
||||
|
||||
// when swap returns, x, y, & temp are popped from the stack
|
||||
// the memory allocated to perm is still in use
|
||||
return perm;
|
||||
}
|
||||
|
||||
|
||||
void* p = swap(b, c);
|
||||
free(p);
|
||||
\end{minted}
|
||||
|
||||
Why not just return \verb|temp| in the same way?
|
||||
\begin{itemize}
|
||||
\item Even when this function terminates, another function can access perm using that pointer.
|
||||
\item If we need to store a large or undeterminable amount of data, we can safely use the heap as there is no risk
|
||||
of stack overflow and no risk of losing reference or accidental de-allocation of memory.
|
||||
\end{itemize}
|
||||
|
||||
\section{Dynamic Memory}
|
||||
FINISH OFF
|
||||
|
||||
\section{Functional Programming}
|
||||
Given the same problem to solve, a program for said problem in any programming language can be considered
|
||||
equivalent to any other at the machine level in that the programs will result in changes to values contained in
|
||||
memory cells.
|
||||
However, there can be quite significant differences at both the conceptual \& implementation level.
|
||||
|
||||
\subsection{Lisp, Racket, \& Scheme}
|
||||
\textbf{LISP} (more commonly referred to as \textbf{Lisp}) is a contraction of \textbf{List Processing}.
|
||||
\textbf{Scheme} is a dialect of Lisp, and \textbf{Racket} is an implementation of Scheme.
|
||||
Lisp uses prefix (Polish) notation, e.g.: \verb|(+ 3 4)|, \verb|(* 5 6)|, \verb|(- 4 (* 5 6))|, etc.
|
||||
|
||||
\subsubsection{Function vs Literal}
|
||||
Parentheses are used to represent a \textbf{function}:
|
||||
\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{lisp}
|
||||
(+ 3 4) ; = 7
|
||||
(* 5 6) ; = 30
|
||||
(- 4 (* 5 6)) ; = -26
|
||||
\end{minted}
|
||||
|
||||
A single quote is used to represent a \textbf{literal}:
|
||||
\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{lisp}
|
||||
(+ 3 4) ; = 7
|
||||
'(+ 3 4) ; = '(+ 3 4)
|
||||
\end{minted}
|
||||
|
||||
Rather than considering \verb|+| as the name of a function, the quote means to take everything literally, i.e.
|
||||
``\verb|+|'' is just a word.
|
||||
Nothing is evaluated.
|
||||
|
||||
\subsubsection{S-Expressions}
|
||||
Both code \& data are structured as nested lists in Lisp.
|
||||
\textbf{Symbolic Expressions} or s-expressions, sexprs, or sexps are a notation for nested list structures.
|
||||
They are defined with a very simple recursive grammar, but produce a very flexible framework for computing.
|
||||
An s-expression is defined as:
|
||||
\begin{enumerate}
|
||||
\item An \textbf{atom}.
|
||||
Atoms are considered to be ``indivisible''.
|
||||
Primitive data types like numbers, strings, booleans, etc. are atoms.
|
||||
Lists \& pairs (s-expressions) are not.
|
||||
\item An expression in the form \verb|(X . Y)|, where \verb|X| \& \verb|Y| are s-expressions.
|
||||
\end{enumerate}
|
||||
|
||||
A \textbf{pair} is two pieces of data together.
|
||||
They are created by the \verb|cons| function, which is short for ``construct'', e.g. \verb|(cons 1 2)|.
|
||||
The two values joined with \verb|cons| are printed between parentheses interspaced by a \verb|.| (a period):
|
||||
\begin{minted}[texcl, mathescape, breaklines, frame=single]{lisp}
|
||||
> (cons "banana" "split")
|
||||
'("banana" . "split")'
|
||||
\end{minted}
|
||||
|
||||
\subsection{Lists}
|
||||
A \textbf{list} is an ordered group of data.
|
||||
List elements are separated by a space.
|
||||
The list syntax is a shorthand for an s-expression.
|
||||
Lists are displayed between parentheses using the \verb|'| (single quote character).
|
||||
\begin{minted}[texcl, mathescape, breaklines, frame=single]{lisp}
|
||||
'(1 2 3) ; list of numbers
|
||||
'("this" "that" "the other") ; list of strings
|
||||
'(1 2 "three" 4) ; list of mixed data types
|
||||
\end{minted}
|
||||
|
||||
Lisp uses nested lists (which are essentially linked lists).
|
||||
We can access the first element of a list using the \verb|car| function:
|
||||
\begin{minted}[texcl, mathescape, breaklines, frame=single]{lisp}
|
||||
> (car '(1 2 3))
|
||||
1
|
||||
\end{minted}
|
||||
|
||||
We can access the rest of the list using the \verb|cdr| function:
|
||||
\begin{minted}[texcl, mathescape, breaklines, frame=single]{lisp}
|
||||
> (cdr '(1 2 3))
|
||||
'(2 3)
|
||||
\end{minted}
|
||||
|
||||
\verb|cdr| is analogous to \verb|element->rest| in our C linked list.
|
||||
\begin{minted}[texcl, mathescape, breaklines, frame=single]{lisp}
|
||||
> (car (cdr '(1 2 3)))
|
||||
2
|
||||
\end{minted}
|
||||
|
||||
There is a shorthand for a combination of \verb|car|s \& \verb|cdr|s (up to 4 operations usually but it depends
|
||||
on the Scheme environment), where \verb|*| is \verb|a| or \verb|d| or a combination (if supported).
|
||||
For example, write a sequence of \verb|car|s \& \verb|cdr|s to extract: ``\verb|d|'' from list
|
||||
\verb|(a b c d e f)| named \verb|lis|:
|
||||
\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{lisp}
|
||||
;;;; these two are equivalent
|
||||
(car (cdr (cdr (cdr lis))))
|
||||
cadddr(lis)
|
||||
\end{minted}
|
||||
|
||||
Lists are really just \verb|cons| pairs where these second element is another list or \verb|empty|;
|
||||
\verb|empty| is a special word, similar to \verb|NULL| in other languages.
|
||||
\begin{minted}[texcl, mathescape, breaklines, frame=single]{lisp}
|
||||
> (cons 2 empty)
|
||||
'(2)
|
||||
|
||||
> (cons 1 (cons 2 empty))
|
||||
'(1 2)
|
||||
\end{minted}
|
||||
|
||||
The built-in functions \verb|list| \& \verb|append| provide a more convenient way to create lists.
|
||||
|
||||
\subsubsection{\texttt{define}}
|
||||
\textbf{\texttt{define}} binds a variable to some data.
|
||||
Its format is \mintinline{lisp}{(define variable value)}.
|
||||
\verb|define| is used for user-defined functions.
|
||||
Note that user-defined functions can be used within other use defined functions as long as the functions are
|
||||
defined before they are invoked.
|
||||
\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{lisp}
|
||||
(define (function_name parameter-list)
|
||||
Function-body
|
||||
)
|
||||
|
||||
;;; calculates the absolute addition of two numbers where the function abs returns the absolute value of a number
|
||||
(define (sumabs num1 num2)
|
||||
(+ (abs num1) (abs num2))
|
||||
)
|
||||
\end{minted}
|
||||
\begin{minted}[texcl, mathescape, breaklines, frame=single]{lisp}
|
||||
> (sumabs 2 -3)
|
||||
5
|
||||
\end{minted}
|
||||
|
||||
\subsubsection{\texttt{list} \& \texttt{append}}
|
||||
The \verb|list| function constructs a list from components.
|
||||
It takes the form \mintinline{lisp}{(list el-1 el-2 el-n)}.
|
||||
These components can be symbols, numbers, or lists.
|
||||
\\\\
|
||||
\verb|append| collects components from several lists into one list.
|
||||
Its arguments must be lists.
|
||||
\verb|append| takes the form \mintinline{lisp}{(append list1 list2 listn)}.
|
||||
|
||||
|
||||
|
||||
\end{document}
|
@ -0,0 +1,3 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k}{sizeof}\PYG{p}{(}\PYG{o}{\PYGZlt{}}\PYG{n}{type}\PYG{o}{\PYGZgt{}}\PYG{p}{)}
|
||||
\end{Verbatim}
|
@ -0,0 +1,15 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}]
|
||||
\PYG{c+cp}{\PYGZsh{}include}\PYG{c+cpf}{\PYGZlt{}stdio.h>}
|
||||
|
||||
\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{swap}\PYG{p}{(}\PYG{k+kt}{int}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{x}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{int}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{y}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}}
|
||||
\PYG{+w}{ }\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{temp}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{o}{*}\PYG{n}{x}\PYG{p}{;}
|
||||
\PYG{+w}{ }\PYG{o}{*}\PYG{n}{x}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{o}{*}\PYG{n}{y}\PYG{p}{;}
|
||||
\PYG{+w}{ }\PYG{o}{*}\PYG{n}{y}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{temp}\PYG{p}{;}
|
||||
\PYG{p}{\PYGZcb{}}
|
||||
|
||||
\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n+nf}{main}\PYG{p}{(}\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{argc}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{char}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{arv}\PYG{p}{[])}\PYG{+w}{ }\PYG{p}{\PYGZob{}}
|
||||
\PYG{+w}{ }\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{a}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{l+m+mi}{8}\PYG{p}{;}
|
||||
\PYG{+w}{ }\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{b}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{l+m+mi}{4}\PYG{p}{;}
|
||||
\PYG{+w}{ }\PYG{n}{swap}\PYG{p}{(}\PYG{o}{\PYGZam{}}\PYG{n}{a}\PYG{p}{,}\PYG{+w}{ }\PYG{o}{\PYGZam{}}\PYG{n}{b}\PYG{p}{);}\PYG{+w}{ }\PYG{c+c1}{// this should make a=4 & b=8}
|
||||
\PYG{p}{\PYGZcb{}}
|
||||
\end{Verbatim}
|
@ -0,0 +1,3 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k+kt}{void}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{memcpy}\PYG{p}{(}\PYG{k+kt}{void}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{to}\PYG{p}{,}\PYG{+w}{ }\PYG{k}{const}\PYG{+w}{ }\PYG{k+kt}{void}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{from}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{size\PYGZus{}t}\PYG{+w}{ }\PYG{n}{size}\PYG{p}{)}
|
||||
\end{Verbatim}
|
@ -0,0 +1,3 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{p}{(}\PYG{n+nv}{define}\PYG{+w}{ }\PYG{n+nv}{variable}\PYG{+w}{ }\PYG{n+nv}{value}\PYG{p}{)}
|
||||
\end{Verbatim}
|
@ -0,0 +1,25 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}]
|
||||
\PYG{c+c1}{// header inclusion: functionally defined in stdio.h is added into the program by the compiler, specifically the Linker step of the compiler}
|
||||
\PYG{c+c1}{// "stdio" is short for "Standard Input / Output"}
|
||||
\PYG{c+cp}{\PYGZsh{}include}\PYG{+w}{ }\PYG{c+cpf}{\PYGZlt{}stdio.h>}
|
||||
|
||||
\PYG{c+c1}{// function prototype: tells the compiler that the function exists before it has been implemented}
|
||||
\PYG{c+c1}{// allows the compiler to handle recursion, or functions calling each other}
|
||||
\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{sayHello}\PYG{p}{();}
|
||||
|
||||
\PYG{c+c1}{// function definition: implements the function}
|
||||
\PYG{c+c1}{// note: data type, arguments, return}
|
||||
\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{sayHello}\PYG{p}{()}\PYG{+w}{ }\PYG{p}{\PYGZob{}}
|
||||
\PYG{+w}{ }\PYG{c+c1}{// calling a function: printf takes a char* argument}
|
||||
\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}Hello World!}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{);}
|
||||
\PYG{p}{\PYGZcb{}}
|
||||
|
||||
\PYG{c+c1}{// main function: the entry point to the progam}
|
||||
\PYG{c+c1}{// returns int}
|
||||
\PYG{c+c1}{// takes two arguments: argc (the number of command-line arguments) & argv (an array of the arguments)}
|
||||
\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n+nf}{main}\PYG{p}{(}\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{argc}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{char}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{argv}\PYG{p}{[])}\PYG{+w}{ }\PYG{p}{\PYGZob{}}
|
||||
\PYG{+w}{ }\PYG{c+c1}{// calling a function: sayhello takes no argument. nothing is returned}
|
||||
\PYG{+w}{ }\PYG{n}{sayHello}\PYG{p}{();}
|
||||
\PYG{+w}{ }\PYG{k}{return}\PYG{+w}{ }\PYG{l+m+mi}{0}\PYG{p}{;}
|
||||
\PYG{p}{\PYGZcb{}}
|
||||
\end{Verbatim}
|
@ -0,0 +1,4 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}]
|
||||
\PYG{n+nb}{\PYGZgt{}}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{car}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cdr}\PYG{+w}{ }\PYG{o}{\PYGZsq{}}\PYG{p}{(}\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{l+m+mi}{2}\PYG{+w}{ }\PYG{l+m+mi}{3}\PYG{p}{)))}
|
||||
\PYG{l+m+mi}{2}
|
||||
\end{Verbatim}
|
@ -0,0 +1,4 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}]
|
||||
\PYG{c+c1}{// pointer p2 points to the address of integer i}
|
||||
\PYG{k+kt}{int}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{p2}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{o}{\PYGZam{}}\PYG{n}{i}\PYG{p}{;}
|
||||
\end{Verbatim}
|
@ -0,0 +1,4 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}]
|
||||
\PYG{p}{(}\PYG{n+nb}{+}\PYG{+w}{ }\PYG{l+m+mi}{3}\PYG{+w}{ }\PYG{l+m+mi}{4}\PYG{p}{)}\PYG{+w}{ }\PYG{c+c1}{; = 7}
|
||||
\PYG{o}{\PYGZsq{}}\PYG{p}{(}\PYG{n+nb}{+}\PYG{+w}{ }\PYG{l+m+mi}{3}\PYG{+w}{ }\PYG{l+m+mi}{4}\PYG{p}{)}\PYG{+w}{ }\PYG{c+c1}{; = '(+ 3 4)}
|
||||
\end{Verbatim}
|
@ -0,0 +1,3 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{p}{(}\PYG{n+nb}{append}\PYG{+w}{ }\PYG{n+nv}{list1}\PYG{+w}{ }\PYG{n+nv}{list2}\PYG{+w}{ }\PYG{n+nv}{listn}\PYG{p}{)}
|
||||
\end{Verbatim}
|
@ -0,0 +1,5 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}]
|
||||
\PYG{o}{\PYGZsq{}}\PYG{p}{(}\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{l+m+mi}{2}\PYG{+w}{ }\PYG{l+m+mi}{3}\PYG{p}{)}\PYG{+w}{ }\PYG{c+c1}{; list of numbers}
|
||||
\PYG{o}{\PYGZsq{}}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}this\PYGZdq{}}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}that\PYGZdq{}}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}the other\PYGZdq{}}\PYG{p}{)}\PYG{+w}{ }\PYG{c+c1}{; list of strings}
|
||||
\PYG{o}{\PYGZsq{}}\PYG{p}{(}\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{l+m+mi}{2}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}three\PYGZdq{}}\PYG{+w}{ }\PYG{l+m+mi}{4}\PYG{p}{)}\PYG{+w}{ }\PYG{c+c1}{; list of mixed data types}
|
||||
\end{Verbatim}
|
@ -0,0 +1,10 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}]
|
||||
\PYG{c+cp}{\PYGZsh{}include}\PYG{+w}{ }\PYG{c+cpf}{\PYGZlt{}string.h>}
|
||||
|
||||
\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{generic\PYGZus{}swap}\PYG{p}{(}\PYG{k+kt}{void}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{vp1}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{void}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{vp2}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{size}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}}
|
||||
\PYG{+w}{ }\PYG{k+kt}{char}\PYG{+w}{ }\PYG{n}{temp\PYGZus{}buff}\PYG{p}{[}\PYG{n}{size}\PYG{p}{];}\PYG{+w}{ }\PYG{c+c1}{// need malloc?}
|
||||
\PYG{+w}{ }\PYG{n}{memcpy}\PYG{p}{(}\PYG{n}{temp\PYGZus{}buff}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{vp1}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{size}\PYG{p}{);}
|
||||
\PYG{+w}{ }\PYG{n}{memcpy}\PYG{p}{(}\PYG{n}{vp1}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{vp2}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{size}\PYG{p}{);}
|
||||
\PYG{+w}{ }\PYG{n}{memcpy}\PYG{p}{(}\PYG{n}{vp2}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{temp\PYGZus{}buff}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{size}\PYG{p}{);}
|
||||
\PYG{p}{\PYGZcb{}}
|
||||
\end{Verbatim}
|
@ -0,0 +1,10 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}]
|
||||
\PYG{p}{(}\PYG{n+nv}{define}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nv}{function\PYGZus{}name}\PYG{+w}{ }\PYG{n+nv}{parameter\PYGZhy{}list}\PYG{p}{)}
|
||||
\PYG{+w}{ }\PYG{n+nv}{Function\PYGZhy{}body}
|
||||
\PYG{p}{)}
|
||||
|
||||
\PYG{c+c1}{;;; calculates the absolute addition of two numbers where the function abs returns the absolute value of a number}
|
||||
\PYG{p}{(}\PYG{n+nv}{define}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nv}{sumabs}\PYG{+w}{ }\PYG{n+nv}{num1}\PYG{+w}{ }\PYG{n+nv}{num2}\PYG{p}{)}
|
||||
\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{+}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{abs}\PYG{+w}{ }\PYG{n+nv}{num1}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{abs}\PYG{+w}{ }\PYG{n+nv}{num2}\PYG{p}{))}
|
||||
\PYG{p}{)}
|
||||
\end{Verbatim}
|
@ -0,0 +1,5 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}]
|
||||
\PYG{p}{(}\PYG{n+nb}{+}\PYG{+w}{ }\PYG{l+m+mi}{3}\PYG{+w}{ }\PYG{l+m+mi}{4}\PYG{p}{)}\PYG{+w}{ }\PYG{c+c1}{; = 7}
|
||||
\PYG{p}{(}\PYG{n+nb}{*}\PYG{+w}{ }\PYG{l+m+mi}{5}\PYG{+w}{ }\PYG{l+m+mi}{6}\PYG{p}{)}\PYG{+w}{ }\PYG{c+c1}{; = 30}
|
||||
\PYG{p}{(}\PYG{n+nb}{\PYGZhy{}}\PYG{+w}{ }\PYG{l+m+mi}{4}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{*}\PYG{+w}{ }\PYG{l+m+mi}{5}\PYG{+w}{ }\PYG{l+m+mi}{6}\PYG{p}{))}\PYG{+w}{ }\PYG{c+c1}{; = -26}
|
||||
\end{Verbatim}
|
@ -0,0 +1,4 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}]
|
||||
\PYG{n+nb}{\PYGZgt{}}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{car}\PYG{+w}{ }\PYG{o}{\PYGZsq{}}\PYG{p}{(}\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{l+m+mi}{2}\PYG{+w}{ }\PYG{l+m+mi}{3}\PYG{p}{))}
|
||||
\PYG{l+m+mi}{1}
|
||||
\end{Verbatim}
|
@ -0,0 +1,5 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}]
|
||||
\PYG{c+c1}{;;;; these two are equivalent}
|
||||
\PYG{p}{(}\PYG{n+nb}{car}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cdr}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cdr}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cdr}\PYG{+w}{ }\PYG{n+nv}{lis}\PYG{p}{))))}
|
||||
\PYG{n+nb}{cadddr}\PYG{p}{(}\PYG{n+nv}{lis}\PYG{p}{)}
|
||||
\end{Verbatim}
|
@ -0,0 +1,4 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}]
|
||||
\PYG{n+nb}{\PYGZgt{}}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nv}{sumabs}\PYG{+w}{ }\PYG{l+m+mi}{2}\PYG{+w}{ }\PYG{l+m+mi}{\PYGZhy{}3}\PYG{p}{)}
|
||||
\PYG{l+m+mi}{5}
|
||||
\end{Verbatim}
|
@ -0,0 +1,29 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}]
|
||||
\PYG{c+cp}{\PYGZsh{}include}\PYG{+w}{ }\PYG{c+cpf}{\PYGZlt{}stdio.h>}
|
||||
|
||||
\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n+nf}{add}\PYG{p}{(}\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{a}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{b}\PYG{p}{);}
|
||||
|
||||
\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n+nf}{add}\PYG{p}{(}\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{a}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{b}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}}
|
||||
\PYG{+w}{ }\PYG{k}{return}\PYG{+w}{ }\PYG{n}{a}\PYG{o}{+}\PYG{n}{b}\PYG{p}{;}
|
||||
\PYG{p}{\PYGZcb{}}
|
||||
|
||||
\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n+nf}{main}\PYG{p}{(}\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{argc}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{char}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{argv}\PYG{p}{[])}\PYG{+w}{ }\PYG{p}{\PYGZob{}}
|
||||
\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}Let\PYGZsq{}s add some numbers...}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{);}
|
||||
\PYG{+w}{ }\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{first}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{l+m+mi}{8}\PYG{p}{;}
|
||||
\PYG{+w}{ }\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{second}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{l+m+mi}{4}\PYG{p}{;}
|
||||
\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}The first number is \PYGZpc{}d}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{first}\PYG{p}{);}
|
||||
\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}The second number is \PYGZpc{}d}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{second}\PYG{p}{);}
|
||||
|
||||
\PYG{+w}{ }\PYG{c+c1}{// "add" is a function that returns an int}
|
||||
\PYG{+w}{ }\PYG{c+c1}{// the returned int is stored in the "result" variable - they must have the same data type}
|
||||
\PYG{+w}{ }\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{result}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{add}\PYG{p}{(}\PYG{n}{first}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{second}\PYG{p}{);}
|
||||
|
||||
|
||||
\PYG{+w}{ }\PYG{c+c1}{// "%d" is for ints - strictly decimal ints}
|
||||
\PYG{+w}{ }\PYG{c+c1}{// "%i" is any int including octal and hexadecimal}
|
||||
\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}When we add them together we get: \PYGZpc{}d}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{result}\PYG{p}{);}
|
||||
|
||||
\PYG{+w}{ }\PYG{k}{return}\PYG{+w}{ }\PYG{l+m+mi}{0}\PYG{p}{;}
|
||||
\PYG{p}{\PYGZcb{}}
|
||||
|
||||
\end{Verbatim}
|
@ -0,0 +1,11 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}]
|
||||
\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{swap}\PYG{p}{(}\PYG{k+kt}{void}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{x}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{void}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{y}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}}
|
||||
\PYG{+w}{ }\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n}{temp}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{o}{*}\PYG{n}{x}\PYG{p}{;}\PYG{+w}{ }\PYG{c+c1}{// won't work!}
|
||||
\PYG{+w}{ }\PYG{c+c1}{// we don't know what size data *x points to, so void temp can't work}
|
||||
\PYG{+w}{ }\PYG{c+c1}{// it is impossible to have a variable of type void for this reason}
|
||||
\PYG{+w}{ }\PYG{c+c1}{// but we can have a pointer of type void*}
|
||||
|
||||
\PYG{+w}{ }\PYG{o}{*}\PYG{n}{x}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{o}{*}\PYG{n}{y}\PYG{p}{;}
|
||||
\PYG{+w}{ }\PYG{o}{*}\PYG{n}{y}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{temp}\PYG{p}{;}
|
||||
\PYG{p}{\PYGZcb{}}
|
||||
\end{Verbatim}
|
@ -0,0 +1,4 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}]
|
||||
\PYG{n+nb}{\PYGZgt{}}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}banana\PYGZdq{}}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}split\PYGZdq{}}\PYG{p}{)}
|
||||
\PYG{o}{\PYGZsq{}}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}banana\PYGZdq{}}\PYG{+w}{ }\PYG{o}{.}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}split\PYGZdq{}}\PYG{p}{)}\PYG{o}{\PYGZsq{}}
|
||||
\end{Verbatim}
|
@ -0,0 +1,4 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}]
|
||||
\PYG{c+c1}{// ineger i2 is assigned the integer value that the pointer p is pointing to}
|
||||
\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{i2}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{o}{*}\PYG{n}{p}\PYG{p}{;}
|
||||
\end{Verbatim}
|
@ -0,0 +1,3 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{p}{(}\PYG{n+nb}{list}\PYG{+w}{ }\PYG{n+nv}{el\PYGZhy{}1}\PYG{+w}{ }\PYG{n+nv}{el\PYGZhy{}2}\PYG{+w}{ }\PYG{n+nv}{el\PYGZhy{}n}\PYG{p}{)}
|
||||
\end{Verbatim}
|
@ -0,0 +1,24 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}]
|
||||
\PYG{c+c1}{// first, b & c are pushed onto the stack}
|
||||
\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{b}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{l+m+mi}{100}\PYG{p}{;}
|
||||
\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{c}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{l+m+mi}{50}\PYG{p}{;}
|
||||
|
||||
\PYG{c+c1}{// when swap() is called, x, y, & temp are pushed onto the stack}
|
||||
\PYG{k+kt}{void}\PYG{o}{*}\PYG{+w}{ }\PYG{n+nf}{swap}\PYG{p}{(}\PYG{k+kt}{int}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{x}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{int}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{y}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}}
|
||||
\PYG{+w}{ }\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{temp}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{o}{*}\PYG{n}{x}\PYG{p}{;}
|
||||
|
||||
\PYG{+w}{ }\PYG{c+c1}{// we allocate space in memory to perm using malloc}
|
||||
\PYG{+w}{ }\PYG{k+kt}{int}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{perm}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{malloc}\PYG{p}{(}\PYG{k+kt}{int}\PYG{p}{);}
|
||||
\PYG{+w}{ }\PYG{n}{perm}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{o}{\PYGZam{}}\PYG{n}{temp}\PYG{p}{;}
|
||||
\PYG{+w}{ }\PYG{n}{x}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{y}\PYG{p}{;}
|
||||
\PYG{+w}{ }\PYG{n}{y}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{o}{*}\PYG{n}{perm}\PYG{p}{;}
|
||||
|
||||
\PYG{+w}{ }\PYG{c+c1}{// when swap returns, x, y, & temp are popped from the stack}
|
||||
\PYG{+w}{ }\PYG{c+c1}{// the memory allocated to perm is still in use}
|
||||
\PYG{+w}{ }\PYG{k}{return}\PYG{+w}{ }\PYG{n}{perm}\PYG{p}{;}
|
||||
\PYG{p}{\PYGZcb{}}
|
||||
|
||||
|
||||
\PYG{k+kt}{void}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{p}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{swap}\PYG{p}{(}\PYG{n}{b}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{c}\PYG{p}{);}
|
||||
\PYG{n}{free}\PYG{p}{(}\PYG{n}{p}\PYG{p}{);}
|
||||
\end{Verbatim}
|
@ -0,0 +1,4 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}]
|
||||
\PYG{n+nb}{\PYGZgt{}}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cdr}\PYG{+w}{ }\PYG{o}{\PYGZsq{}}\PYG{p}{(}\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{l+m+mi}{2}\PYG{+w}{ }\PYG{l+m+mi}{3}\PYG{p}{))}
|
||||
\PYG{o}{\PYGZsq{}}\PYG{p}{(}\PYG{l+m+mi}{2}\PYG{+w}{ }\PYG{l+m+mi}{3}\PYG{p}{)}
|
||||
\end{Verbatim}
|
@ -0,0 +1,17 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}]
|
||||
\PYG{c+c1}{// first, a, b, & c are pushed onto the stack}
|
||||
\PYG{k+kt}{char}\PYG{+w}{ }\PYG{n}{a}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{l+s+sc}{\PYGZsq{}a\PYGZsq{}}\PYG{p}{;}
|
||||
\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{b}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{l+m+mi}{100}\PYG{p}{;}
|
||||
\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{c}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{l+m+mi}{50}\PYG{p}{;}
|
||||
|
||||
\PYG{c+c1}{// when swap() is called, x, y, & temp are pushed onto the stack}
|
||||
\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{swap}\PYG{p}{(}\PYG{k+kt}{int}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{x}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{int}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{y}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}}
|
||||
\PYG{+w}{ }\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{temp}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{o}{*}\PYG{n}{x}\PYG{p}{;}
|
||||
\PYG{+w}{ }\PYG{o}{*}\PYG{n}{x}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{o}{*}\PYG{n}{y}\PYG{p}{;}
|
||||
\PYG{+w}{ }\PYG{o}{*}\PYG{n}{y}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{temp}\PYG{p}{;}
|
||||
|
||||
\PYG{+w}{ }\PYG{c+c1}{// when swap returns, x, y, & temp are popped from the stack and \textbf{their memory is no longer in use}}
|
||||
\PYG{p}{\PYGZcb{}}
|
||||
|
||||
\PYG{n}{swap}\PYG{p}{(}\PYG{n}{b}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{c}\PYG{p}{);}
|
||||
\end{Verbatim}
|
@ -0,0 +1,7 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}]
|
||||
\PYG{n+nb}{\PYGZgt{}}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+m+mi}{2}\PYG{+w}{ }\PYG{n+nv}{empty}\PYG{p}{)}
|
||||
\PYG{o}{\PYGZsq{}}\PYG{p}{(}\PYG{l+m+mi}{2}\PYG{p}{)}
|
||||
|
||||
\PYG{n+nb}{\PYGZgt{}}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+m+mi}{2}\PYG{+w}{ }\PYG{n+nv}{empty}\PYG{p}{))}
|
||||
\PYG{o}{\PYGZsq{}}\PYG{p}{(}\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{l+m+mi}{2}\PYG{p}{)}
|
||||
\end{Verbatim}
|
@ -0,0 +1,3 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k+kt}{void}\PYG{o}{*}
|
||||
\end{Verbatim}
|
@ -0,0 +1,10 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}]
|
||||
\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{intArr}\PYG{p}{[}\PYG{l+m+mi}{5}\PYG{p}{];}\PYG{+w}{ }\PYG{c+c1}{// an integer array of size 5}
|
||||
\PYG{c+c1}{// intArr is a pointer to the 0th element of the array - the same as &intArr[0]}
|
||||
|
||||
\PYG{n}{intArr}\PYG{p}{[}\PYG{l+m+mi}{2}\PYG{p}{]}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{l+m+mi}{3}\PYG{p}{;}\PYG{+w}{ }\PYG{c+c1}{// same as *(intArr+2) = 3;}
|
||||
\PYG{c+c1}{// (intArr + 2) is of type (int*) while intArr[2] is of type int}
|
||||
\PYG{c+c1}{// in the latter case, the pointer is dereferenced}
|
||||
\PYG{c+c1}{// (intArr + 2) is the same as (&(intArr[2]))}
|
||||
\PYG{c+c1}{// note that the + operator here is not simple addition - it moves the pointer by the size of the type}
|
||||
\end{Verbatim}
|
@ -0,0 +1,4 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}]
|
||||
\PYG{k+kt}{int}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{p}\PYG{p}{;}\PYG{+w}{ }\PYG{c+c1}{// variable p is a pointer to an integer value}
|
||||
\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{i}\PYG{p}{;}\PYG{+w}{ }\PYG{c+c1}{// integer value}
|
||||
\end{Verbatim}
|
@ -0,0 +1,76 @@
|
||||
|
||||
\makeatletter
|
||||
\def\PYG@reset{\let\PYG@it=\relax \let\PYG@bf=\relax%
|
||||
\let\PYG@ul=\relax \let\PYG@tc=\relax%
|
||||
\let\PYG@bc=\relax \let\PYG@ff=\relax}
|
||||
\def\PYG@tok#1{\csname PYG@tok@#1\endcsname}
|
||||
\def\PYG@toks#1+{\ifx\relax#1\empty\else%
|
||||
\PYG@tok{#1}\expandafter\PYG@toks\fi}
|
||||
\def\PYG@do#1{\PYG@bc{\PYG@tc{\PYG@ul{%
|
||||
\PYG@it{\PYG@bf{\PYG@ff{#1}}}}}}}
|
||||
\def\PYG#1#2{\PYG@reset\PYG@toks#1+\relax+\PYG@do{#2}}
|
||||
|
||||
\@namedef{PYG@tok@c}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}}
|
||||
\@namedef{PYG@tok@cp}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}}
|
||||
\@namedef{PYG@tok@cs}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}}
|
||||
\@namedef{PYG@tok@k}{\let\PYG@bf=\textbf}
|
||||
\@namedef{PYG@tok@kd}{\let\PYG@bf=\textbf\let\PYG@it=\textit}
|
||||
\@namedef{PYG@tok@nb}{\let\PYG@bf=\textbf\let\PYG@it=\textit}
|
||||
\@namedef{PYG@tok@bp}{\let\PYG@bf=\textbf\let\PYG@it=\textit}
|
||||
\@namedef{PYG@tok@nn}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@nc}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@nf}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@nv}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@no}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@ow}{\let\PYG@bf=\textbf}
|
||||
\@namedef{PYG@tok@s}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@err}{\def\PYG@bc##1{{\setlength{\fboxsep}{\string -\fboxrule}\fcolorbox[rgb]{1.00,0.00,0.00}{1,1,1}{\strut ##1}}}}
|
||||
\@namedef{PYG@tok@kc}{\let\PYG@bf=\textbf}
|
||||
\@namedef{PYG@tok@kn}{\let\PYG@bf=\textbf}
|
||||
\@namedef{PYG@tok@kp}{\let\PYG@bf=\textbf}
|
||||
\@namedef{PYG@tok@kr}{\let\PYG@bf=\textbf}
|
||||
\@namedef{PYG@tok@kt}{\let\PYG@bf=\textbf}
|
||||
\@namedef{PYG@tok@fm}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@vc}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@vg}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@vi}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@vm}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@sa}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@sb}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@sc}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@dl}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@sd}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@s2}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@se}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@sh}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@si}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@sx}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@sr}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@s1}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@ss}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@ch}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}}
|
||||
\@namedef{PYG@tok@cm}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}}
|
||||
\@namedef{PYG@tok@cpf}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}}
|
||||
\@namedef{PYG@tok@c1}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}}
|
||||
|
||||
\def\PYGZbs{\char`\\}
|
||||
\def\PYGZus{\char`\_}
|
||||
\def\PYGZob{\char`\{}
|
||||
\def\PYGZcb{\char`\}}
|
||||
\def\PYGZca{\char`\^}
|
||||
\def\PYGZam{\char`\&}
|
||||
\def\PYGZlt{\char`\<}
|
||||
\def\PYGZgt{\char`\>}
|
||||
\def\PYGZsh{\char`\#}
|
||||
\def\PYGZpc{\char`\%}
|
||||
\def\PYGZdl{\char`\$}
|
||||
\def\PYGZhy{\char`\-}
|
||||
\def\PYGZsq{\char`\'}
|
||||
\def\PYGZdq{\char`\"}
|
||||
\def\PYGZti{\char`\~}
|
||||
% for compatibility with earlier versions
|
||||
\def\PYGZat{@}
|
||||
\def\PYGZlb{[}
|
||||
\def\PYGZrb{]}
|
||||
\makeatother
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 58 KiB |
Binary file not shown.
After Width: | Height: | Size: 107 KiB |
Binary file not shown.
After Width: | Height: | Size: 144 KiB |
Reference in New Issue
Block a user