Date post: | 11-Feb-2018 |
Category: |
Documents |
Upload: | christopher-vizcarra |
View: | 241 times |
Download: | 0 times |
of 73
7/23/2019 Lisp Slides
1/73
FunctionalProgramming
7/23/2019 Lisp Slides
2/73
Functional programming
The primary method of computation is the
application of functions to arguments
Immutable & stateless
Allows less error, cleaner, and elegant code
7/23/2019 Lisp Slides
3/73
Problem domain
Academic Discussion
Mathematical Evaluation
Software Simulation Training (AI)
Financial Computation
Web Development Hardware Design
7/23/2019 Lisp Slides
4/73
History and evolution
at the very foundation, the basis of most
functional programming language is
Lambda Calculus
a formal system in mathematical logic
(especially in computational)
theoretical framework for describing
functions & their evaluation
7/23/2019 Lisp Slides
5/73
Existing languages Lisp
early functional language. introduced several
features for functional-flavored programming
languages Intermediate Programming Language(IPL)
first computer based functional programming language.
assembly-styled FORTRAN
Hope
Rex
7/23/2019 Lisp Slides
6/73
Important
conceptsIn functional programming
7/23/2019 Lisp Slides
7/73
First class and higher order functions
FC: ComSci
HO: Math
Functions that take in functions as arguments
Differential operator
7/23/2019 Lisp Slides
8/73
First class and higher order functions
Application
Partial Application and Currying:
applying arguments one at a time, returning a newfunction that takes the next argument
a + b * c a.add(b.multiply(c))
7/23/2019 Lisp Slides
9/73
Recursion
Iteration is often expressed
as recursion
Tail Recursion:
the function is called at the end of the function
often optimized in Functional Programming during
compilation
7/23/2019 Lisp Slides
10/73
Pure functions
Functions that only returns a value
do not modify any state, like changing thevalue of a global variable
this restricted action is called a side effect
7/23/2019 Lisp Slides
11/73
Pure functions
Allows For Optimization
removal run in parallel (threading)
function reordering memoization
7/23/2019 Lisp Slides
12/73
evaluation
StrictFail at 1/0
non-strict4
print length([2+1, 3*2, 1/0, 5-4])
WHY?
7/23/2019 Lisp Slides
13/73
evaluation
StrictEvaluates everything
non-strictOnly evaluates when needed
print length([2+1, 3*2, 1/0, 5-4])
7/23/2019 Lisp Slides
14/73
LISP
7/23/2019 Lisp Slides
15/73
7/23/2019 Lisp Slides
16/73
LIST PROCESSING
7/23/2019 Lisp Slides
17/73
LIST PROCESSING
7/23/2019 Lisp Slides
18/73
1956 1958 1981
second-oldest programming language that is still in widespread use
Next toFORTRAN
7/23/2019 Lisp Slides
19/73
19561958 1981
CONCEPTUALIZED
7/23/2019 Lisp Slides
20/73
7/23/2019 Lisp Slides
21/73
lisp Initially designed for performing mathematical
notations
LAMBDA CALCUluS
Favored by researchers in Artificial Intelligencefor its capacitY and support for s y m b o l i c
programming
1956 1958 19811958
A l o n z o C h u r c h
7/23/2019 Lisp Slides
22/73
lisp Initially designed for performing mathematical
notations
LAMBDA CALCUluS
Favored by researchers in Artificial Intelligencefor its capacitY & support for s y m b o l i c
programming
1956 1958 19811958
7/23/2019 Lisp Slides
23/73
MacLisp ZetaLisp
Scheme Interlisp
DIALECTS OF lisp
1956 1958 1981
1980s
7/23/2019 Lisp Slides
24/73
LISP MACHINES Runs entirely on lisp Need for power to run
complex aI software
Distributed bycompanies with
their own versions
First single-userworkstations
1956 1958 1981
1980s
7/23/2019 Lisp Slides
25/73
1956 1958
COMMON LISP PROBLEM: large number of lisp dialects
May cause lisp community
Solution: standardize a new language
Have best features of lisp dialects
1981
7/23/2019 Lisp Slides
26/73
PROGRAMMING PARADIGMS
Functional Procedural
Reflective Meta
7/23/2019 Lisp Slides
27/73
BASIC STRUCTURE
( )
7/23/2019 Lisp Slides
28/73
Symbolic expressions
3 valid objects:ATOMLIST
STRING
LISP EXPRESSIONS
7/23/2019 Lisp Slides
29/73
7/23/2019 Lisp Slides
30/73
LIST
()
(yo)
(atom1 atom2)
(atom1 (atom2inlist) atom3)
7/23/2019 Lisp Slides
31/73
7/23/2019 Lisp Slides
32/73
SPECIAL SYMBOLS
Tset of all objects (True, yes, 1)
nilempty data type (False, no, 0)
7/23/2019 Lisp Slides
33/73
7/23/2019 Lisp Slides
34/73
Read-Evaluate-print-loop
REPL
Check source code in repeated loop
Reads symbolic expression, evaluatesit, and prints the result
7/23/2019 Lisp Slides
35/73
PREFIX NOTATION
Operands come after the operators
(+ 2 3)
(+ 1 2 3)
7/23/2019 Lisp Slides
36/73
NAMES Identifiers are symbols (variables in
terms of form)
composed of alphanumeric characters,underscores, and hyphens
this-asymbol_5
anothersymbol
7/23/2019 Lisp Slides
37/73
7/23/2019 Lisp Slides
38/73
LIFETIME
Dynamic variables in Lisp have indefinite
lifetimes stay until everything finishesrunning
Variables bound with let only last untilthe end of the defining form
7/23/2019 Lisp Slides
39/73
Data Types
Set of objects
Each object belongs to at least onedata type
Explicit declaration of data type isnot necessary
7/23/2019 Lisp Slides
40/73
FUNCTIONS ON Data Types
Typepdetermines if a certain object belongs to a certain
set/data type which returns a value of t if itbelongs to the set and nil if not
Type-ofReturns data type of an object
7/23/2019 Lisp Slides
41/73
Data types: numbers
Integer fixnum - expressible within machine range (e.g. 1, -1, 500)
bignum - integers that do not fall under fixnum (e.g. 25!)
Ratiofractional form of a/b expressed in code as / a b)
Floating point
decimal form (e.g. 4.589, -10.2, 3.00.)
Complex numbersnumbers with imaginary components a+bi is expressed as #C(a b)
7/23/2019 Lisp Slides
42/73
7/23/2019 Lisp Slides
43/73
Data types: characters
Standard characters
begin with #\ followed by any of the following characters:
! @ # $ % & * + ( ) - , . / < > ? ; : { }\ ~ [ ] | ^ _ = `
A.Z
a.z
0...9
Special characters#\Backspace, #\Tab, #\linefeed
7/23/2019 Lisp Slides
44/73
Data types: others
Arrays
Vectors
Hash tablesseries of elements with key and value component
Listmost important data type since lisp is heavy on list processing
7/23/2019 Lisp Slides
45/73
7/23/2019 Lisp Slides
46/73
7/23/2019 Lisp Slides
47/73
If
Progn is used to block multiple statements &
returns the value of the final statement
7/23/2019 Lisp Slides
48/73
7/23/2019 Lisp Slides
49/73
case
7/23/2019 Lisp Slides
50/73
7/23/2019 Lisp Slides
51/73
LOOP for
7/23/2019 Lisp Slides
52/73
do
7/23/2019 Lisp Slides
53/73
subprograms
7/23/2019 Lisp Slides
54/73
7/23/2019 Lisp Slides
55/73
7/23/2019 Lisp Slides
56/73
STRENGTHS AND
WEAKNESSES
7/23/2019 Lisp Slides
57/73
Strengths
Garbage Collection
Dynamic Typing
Support for macros
every programmer can make his own extension
Powerful Error Handling
signaling
handling
restarting
7/23/2019 Lisp Slides
58/73
Strengths
Decent Performance
relative to C++, Lisp is slower by just 1-2 times
compared to Python which is 2-100 times slower.
Portable across hardware and OS
7/23/2019 Lisp Slides
59/73
7/23/2019 Lisp Slides
60/73
Weaknesses
Support for macros
Common Lisp
Scheme
Clojure
Dynamic Typing
strong vs weak typing
7/23/2019 Lisp Slides
61/73
Comparative
critique
7/23/2019 Lisp Slides
62/73
WITH SCHEME
Scheme more minimalisticCommon Lisp more functions
More numerical support on Lisp
Tail calls are optimized in Scheme, possible inCommon Lisp but not required
7/23/2019 Lisp Slides
63/73
WITH SCHEME
Scheme has one namespace
Common Lisp has separate namespacesfor functions and objects (i.e.
you may have a function andan object with the same name)
7/23/2019 Lisp Slides
64/73
7/23/2019 Lisp Slides
65/73
WITH python
One namespace in PythonPython has distinctions for statements and
expressions; everything in Common Lisp is an expression
Objects are prevalent in both languages
Both languages employ automatic garbage collection
7/23/2019 Lisp Slides
66/73
CURRENT
IMPLEMENTATIONS
7/23/2019 Lisp Slides
67/73
Current implementations Several other implementations of Lisp exist apart from
Common, including:
1. CLISP
2. CMUCL (main goal is ANSI compatibility)3. ECL (Embeddable CL)4. CCL (Clozure CL)5. SBCL6. ABCL (Armed Bear CL, runs on Java)7. MKCL
7/23/2019 Lisp Slides
68/73
Real life applications
Authorizers Assistant is a system
used by American Express for
authorizing transactions
7/23/2019 Lisp Slides
69/73
Real life applications
SPIKE schedules the observationperiods of NASAs Hubble Space
Telescope
7/23/2019 Lisp Slides
70/73
Real life applications
The visual language PWGL is used for
synthesizing sounds & aiding
musical composition
Real life applications
7/23/2019 Lisp Slides
71/73
Real life applications
Mirai, a 3D animation suite, was used to animate the
face of Gollum
7/23/2019 Lisp Slides
72/73
DEMO
7/23/2019 Lisp Slides
73/73
Quiz