SlideShare a Scribd company logo
Didn’t code in ages.
HaXe got in the way.




                       LISP
or how I learned to stop worrying and
           love parentheses
; Clojure - a new dialect of LISP

(defn hello [name]
 (println "Hello," name, "!"))

(hello "TryHarder")
but we’re going to talk about more
           than just LISP
what is functional programming?
the history of functional programming
why did functional programming
  become so popular (again)?
or commonly used OO




              the differences between FP and
                 imperative programming
analyze the current usage of
 object-oriented languages
accidental complexity
let’s have a look at object-oriented
programming languages and their
        programming model
there are lots and lots of object-oriented
           languages out there
JAVA
  C#
  AS3
HaXe
Python
 Ruby
  PHP
   ...
but actually they aren’t really that
             different
similar features:
Still we have religious
fights about them!




                                Classes
                             Inheritance
                            Polymorphism
                               Closures
                              imperative
                                   ...
Still we have religious
fights about them!




                          slightly different styles:
                                   Indentation
                                   Semicolons
                                 Syntactic sugar
                                       ...
is this the holy grail of programming?
are we done?
accidental complexity
   “Accidental complexity is complexity that arises in
computer programs or their development process which
  is non-essential to the problem to be solved. While
    essential complexity is inherent and unavoidable,
accidental complexity is caused by the approach chosen
                 to solve the problem.”
Causes side effects
Factories or Dependency


                          variables vs. values
Injection are a sign of
Accidental Complexity




                          class Rhino
                          {
                          	

 private var _position:Point;

                          	

   public function Rhino(position:Point)
                          	

   {
                          	

   	

 _position = position;
                          	

   	

 or
                          	

   	

 _position = position.clone();
                          	

   }
                          }
Side effects

Everyone needs to
observe everyone.   observers / dispatching events
The environment stops
when observing it.




                    var rhino:Rhino = new Rhino();
                    var water:Water = new Water();
                    rhino.addEventlistender(Event.RHINO_JUMP, water.splash);
mutability and state


Mutability and state are accidental complexity.
We are to familiar with
OO to see the problems.




        Most programmers see syntax and and expressivity as the key features
                           in a programming language.

        Whereas we really run into problems understanding larger applications
         and also the effect that changes will take are very hard to predict.
A builder doesn’t need to


                                       building blocks
know what happens
inside a brick.

Pointers in C




                   Object-oriented programming/design is meant to simplify our
                  lives by using object-oriented modules/libraries as our building
                                      blocks for our program.

                      But without knowing the internals this is almost impossible.

                            (Pure) Functions are a far better fit for this purpose.
“Civilization advances by extending the
number of important operations which
   we can perform without thinking.”
         Alfred North Whitehead
now imagine you don’t know
       anything about
object-oriented programming
the history of functional-programming
Math theory:
Definition of functions
Their application

Functional languages
were developed to have a
clearer approach to
mathematics




                                lambda calculus
                           by Alonzo Church in 1930
functional-programming languages

          1959 	

   Lisp
          1975 	

   ML, FP, Scheme
          1986 	

   Standard ML
          1990 	

   Haskell, Erlang
          2000 	

   OCaml
          2003 	

   Scala
          2005 	

   F#
          2007 	

   Clojure
what is functional-programming?
They talk about
algorithms, ds, recursion,
scope ... on page 216
they introduce
ASSIGNEMENT

Available for free online.
In a restricted sense: functional programming means
programming without mutable variables, assignments, loops
            or imperative control structures.
In a wider sense: functional programming means to focus on functions.
In particular: functions can be values that are produced,
           can be consumed and composed.
what is essential in a language
for functional programming?
higher-order function


It has to be possible to use functions as in input or return values in other
                                 functions
function curryMe(input:Function):Function
{
	

 return curry(input, 2);
}
first-class functions


It has to be possible to declare functions anywhere, even inside other functions
function outerFunction():int
{
	

 function innerFunction():int
	

 {
	

 	

 return 0;
	

 }
	

 return innerFunction();
}
recursion


It has to be possible to call functions recursively
function sum(xs:Array):int
{
	

 if(xs.length == 0) return 0;
	

 return xs.shift() + sum(xs);
}
pure functions

    Take and/or return values
   Local scope: no side effects
  Same arguments: same result
Easy to understand, change & test
function pure(x:int, y:int):int
{
	

 return x + y;
}

var _y:int = 1000;
function notPure(x:int):int
{
	

 return x + _y;
}
No classes, what types


                           data-structures
do we have??

Just use basic types
(Lists) and operate on
them.

Basically the same as we
already.

Code == Data



           "It is better to have 100 functions operate on one data
           structure than to have 10 functions operate on 10 data
                           structures." - Alan J. Perlis
why did functional-programming did
become so popular (again) recently?
Clojure
 F#
 Scala




new functional-programming languages
     are popping up left and right
Clojure
F#
Scala




          Moores law
Single-Threaded clock
speed has stalled.
Number of cores
increases.
In a couple of years we
will have laptops with
32 or 64 cores.
examples
//AS3
a + b;
a * b;

;Clojure
(+ a b)
(* a b)
//AS3
Math.max(a, b);

;Clojure
(max a b)
//AS3
function add(x:int,y:int):int
{
  return x + y;
}

;Clojure
(defn add [x, y]
 (+ x y))
//AS3
function fibonacci( a:int ):int
{
  if( a == 0 || a == 1 )
    return a;
  else
    return fib( a - 1 ) + fib( a - 2 );
}
;Clojure
(defn fib [n]
   (if (= n 0) 0
       (if (= n 1) 1
           (+ (fib (- n 1)) (fib (- n 2))))))
;Clojure - whole fibonacci sequence
(defn lazy-seq-fibo
   ([]
       (concat [0 1] (lazy-seq-fibo 0 1)))
   ([a b]
       (let [n (+ a b)]
          (lazy-seq
              (cons n (lazy-seq-fibo b n))))))
(defn neighbours [[x y]]
 (for [dx [-1 0 1] dy (if (zero? dx) [-1 1] [-1 0 1])]
   [(+ dx x) (+ dy y)]))

(defn step [cells]
 (set (for [[loc n] (frequencies (mapcat neighbours cells))
         :when (or (= n 3) (and (= n 2) (cells loc)))]
      loc)))
Runs on the JVM

Interoperability with
Java libraries




                        why clojure?

More Related Content

KEY
Incremental Development with Lisp: Building a Game and a Website
PDF
Lisp for Python Programmers
PDF
Sugaring Lisp for the 21st Century
PDF
Redesigning Common Lisp
PDF
Seeking Clojure
PDF
Csp scala wixmeetup2016
PDF
Scala : language of the future
PDF
Haskell - Being lazy with class
Incremental Development with Lisp: Building a Game and a Website
Lisp for Python Programmers
Sugaring Lisp for the 21st Century
Redesigning Common Lisp
Seeking Clojure
Csp scala wixmeetup2016
Scala : language of the future
Haskell - Being lazy with class

What's hot (20)

PDF
あなたのScalaを爆速にする7つの方法
PDF
How to write a TableGen backend
PPTX
Scala Refactoring for Fun and Profit
PDF
Live coding scala 'the java of the future'
PPT
Lisp Programming Languge
PDF
Practical REPL-driven Development with Clojure
PDF
Weaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
PPTX
The Sincerest Form of Flattery
PPTX
Scala - The Simple Parts, SFScala presentation
PDF
Java Full Throttle
PDF
Clojure made-simple - John Stevenson
PPTX
Speaking Scala: Refactoring for Fun and Profit (Workshop)
PDF
Clojure, Plain and Simple
PPTX
Understanding Javascript Engines
PDF
Triton and symbolic execution on gdb
PDF
re-frame à la spec
PDF
"Simple Made Easy" Made Easy
PDF
JDK8 Functional API
PPTX
Introduction to Kotlin Language and its application to Android platform
PPTX
DevNexus 2018: Learn Java 8, lambdas and functional programming
あなたのScalaを爆速にする7つの方法
How to write a TableGen backend
Scala Refactoring for Fun and Profit
Live coding scala 'the java of the future'
Lisp Programming Languge
Practical REPL-driven Development with Clojure
Weaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
The Sincerest Form of Flattery
Scala - The Simple Parts, SFScala presentation
Java Full Throttle
Clojure made-simple - John Stevenson
Speaking Scala: Refactoring for Fun and Profit (Workshop)
Clojure, Plain and Simple
Understanding Javascript Engines
Triton and symbolic execution on gdb
re-frame à la spec
"Simple Made Easy" Made Easy
JDK8 Functional API
Introduction to Kotlin Language and its application to Android platform
DevNexus 2018: Learn Java 8, lambdas and functional programming
Ad

Similar to LISP: How I Learned To Stop Worrying And Love Parantheses (20)

PPTX
ScalaDays 2013 Keynote Speech by Martin Odersky
PDF
Clojure and The Robot Apocalypse
PPTX
About Functional Programming
PPTX
Knowledge of Javascript
PDF
Domain specific languages and Scala
PDF
Fp for the oo programmer
PDF
Functional OO programming (as part of the the PTT lecture)
PDF
Presentation
PDF
IN4308 1
PDF
Go Beyond Higher Order Functions: A Journey into Functional Programming
ODP
Clojure
PPTX
Intro to Functional Programming
KEY
Scala: functional programming for the imperative mind
PPTX
Introduction to scala for a c programmer
PPTX
Javascript
PPTX
LISP: назад в будущее, Микола Мозговий
PDF
Functional programming is the most extreme programming
PDF
Beyond Ruby (RubyConf Argentina 2011)
PPT
Douglas Crockford Presentation Goodparts
ScalaDays 2013 Keynote Speech by Martin Odersky
Clojure and The Robot Apocalypse
About Functional Programming
Knowledge of Javascript
Domain specific languages and Scala
Fp for the oo programmer
Functional OO programming (as part of the the PTT lecture)
Presentation
IN4308 1
Go Beyond Higher Order Functions: A Journey into Functional Programming
Clojure
Intro to Functional Programming
Scala: functional programming for the imperative mind
Introduction to scala for a c programmer
Javascript
LISP: назад в будущее, Микола Мозговий
Functional programming is the most extreme programming
Beyond Ruby (RubyConf Argentina 2011)
Douglas Crockford Presentation Goodparts
Ad

LISP: How I Learned To Stop Worrying And Love Parantheses

Editor's Notes