Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Programming
Functional programming
The primary method of computation is the
application of functions to arguments
Problem domain
Academic Discussion
Mathematical Evaluation
Software Simulation Training (AI)
Financial Computation
Web Development
Hardware Design
Lambda Calculus
a formal system in mathematical logic
(especially in computational)
theoretical framework for describing
functions & their evaluation
Existing languages
Lisp
FORTRAN
Hope
Rex
Important
concepts
In functional programming
Differential operator
a + b * c a.add(b.multiply(c))
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
Pure functions
Functions that only returns a value
do not modify any state, like changing the
value of a global variable
this restricted action is called a side effect
Pure functions
Allows For Optimization
removal
run in parallel (threading)
function reordering
memoization
evaluation
print length([2+1, 3*2, 1/0, 5-4])
Strict
Fail at 1/0
non-strict
4
WHY?
evaluation
print length([2+1, 3*2, 1/0, 5-4])
Strict
Evaluates everything
non-strict
Only evaluates when needed
LISP
LIST PROCESSING
LIST PROCESSING
LIST PROCESSING
1956
FORTRAN
1958
1981
CONCEPTUALIZED
1956
1958
1981
John McCarthy
1956
1958
1981
lisp
Alonzo Church
1956
1958
1958
1981
lisp
1956
1958
1958
1981
DIALECTS OF lisp
MacLisp
ZetaLisp
Scheme
Interlisp
1980s
1956
1958
1981
LISP MACHINES
1956
1958
1980s
1981
COMMON LISP
1956
1958
1981
PROGRAMMING PARADIGMS
Functional
Procedural
Reflective
Meta
BASIC STRUCTURE
LISP EXPRESSIONS
Symbolic expressions
3 valid objects:
ATOM
LIST
STRING
ATOM
yo
thisIsAnAtom
atomA
LIST
()
(yo)
(atom1 atom2)
(atom1 (atom2inlist) atom3)
STRING
yo
thisIsAString
Hallo world!
SPECIAL SYMBOLS
T
set of all objects (True, yes, 1)
nil
empty data type (False, no, 0)
INTERPRETED
&
COMPILED
Read-Evaluate-print-loop
REPL
Check source code in repeated loop
Reads symbolic expression, evaluates
it, and prints the result
PREFIX NOTATION
Operands come after the operators
(+ 2 3)
(+ 1 2 3)
NAMES
Identifiers are symbols (variables in
terms of form)
composed of alphanumeric characters,
underscores, and hyphens
this-asymbol_5
anothersymbol
TYPE-CHECKING
BINDING
DYNAMIC BINDING
SCOPING
Static scoping
LIFETIME
Dynamic variables in Lisp have indefinite
lifetimes stay until everything finishes
running
Variables bound with let only last until
the end of the defining form
Data Types
Set of objects
Each object belongs to at least one
data type
Explicit declaration of data type is
not necessary
Type-of
Returns data type of an object
Ratio
fractional form of a/b expressed in code as (/ a b)
Floating point
decimal form (e.g. 4.589, -10.2, 3.00.)
Complex numbers
Nil
false
Special characters
#\Backspace, #\Tab, #\linefeed
Hash tables
series of elements with key and value component
List
most important data type since lisp is heavy on list processing
symbols
composed of alphanumeric characters, underscores, and
hyphens
Control structures
Conditional
If
When
single variable variant of if
returns NIL when condition is not met
UNLESS
single variable variant of if
returns NIL when condition is met
case
LOOP
LOOP for
do
subprograms
subprograms
subprograms
STRENGTHS AND
WEAKNESSES
Strengths
Garbage Collection
Dynamic Typing
Support for macros
every programmer can make his own extension
Strengths
Decent Performance
relative to C++, Lisp is slower by just 1-2 times
compared to Python which is 2-100 times slower.
Weaknesses
Readability
namespace
parentheses
prefix notation
Weaknesses
Support for macros
Common Lisp
Scheme
Clojure
Dynamic Typing
strong vs weak typing
Comparative
critique
WITH SCHEME
Scheme more minimalistic
Common Lisp more functions
More numerical support on Lisp
Tail calls are optimized in Scheme, possible in
Common Lisp but not required
WITH SCHEME
Scheme has one namespace
Common Lisp has separate namespaces
WITH python
Python is more dynamic than Lisp, so harder
to check for errors
WITH python
Python
One namespace in
has distinctions for statements and
expressions; everything in Common Lisp is an expression
Python
CURRENT
IMPLEMENTATIONS
Current implementations
Several other implementations of Lisp exist apart from
Common, including:
1.
2.
3.
4.
5.
6.
7.
CLISP
CMUCL (main goal is ANSI compatibility)
ECL (Embeddable CL)
CCL (Clozure CL)
SBCL
ABCL (Armed Bear CL, runs on Java)
MKCL
DEMO
Quiz