Share
Embed
My Journey in Learning LISP
Membahas tentang bahasa pemrograman LISP ( List Programming ), tentang prinsip - prinsip pemrograman LISP yang jarang ditemui dan direpresentasikan oleh bahasa pemrograman yang lain. Disertai juga dengan demo tentang implementasi Machine Learning dengan modern LISP yaitu Clojure.
KMKLabs
March 14, 2016
Transcript
25 slides
-
Why LISP • LISP is one of ancient technology in
History, 1958 • LISP is based on Pure FP • LISP is said to be core of creational the other modern Programming Language ( Python, Ruby, etc ). -
LISP is • LISP is pure functional programming language that
come from “List Programming”. One of the uniqueness of LISP from other programming language is “Expression-Based” language. -
LISP Story • I started learning LISP about 5 month
ago, because someone suggest me that LISP is one of a rare programming language that people not learn nowadays. Hype Mode: On! I was learning LISP then. -
Expression Based Programming 1 + 1 + 1 + 1
+ 1 + 1 = (+ 1 1 1 1 1 1) (operator arguments) -
Evaluation Order on LISP Applicative Order (sum-of-squares (+ 5 1)
(* 5 2)) (sum-of-squares 6 10) 136 (defn p [] (if (conditional) 1 (p)) Normal Order (sum-of-squares (+ 5 1) (* 5 2)) (+ (square (+ 5 1)) (square (* 5 2)) ) (+ (* (+ 5 1) (+ 5 1)) (* (* 5 2) (* 5 2))) (+ (* 6 6) (* 10 10)) (+ 36 100) 136 -
Procedures as black-box abstraction sqrt is a function to find
square-root’s value of a number by using newton’s method. -
Recursive Linear - Recursion (factorial 6) (* 6 (factorial 5))
(* 6 (* 5 (factorial 4))) (* 6 (* 5 (* 4 (factorial 3)))) (* 6 (* 5 (* 4 (* 3 (factorial 2))))) (* 6 (* 5 (* 4 (* 3 (* 2 1)))))) Iterative - Recursion (factorial 6) (fact-iter 1 1 6) (fact-iter 1 2 6) (fact-iter 2 3 6) (fact-iter 6 4 6) (fact-iter 24 5 6) (fact-iter 120 6 6) (fact-iter 720 7 6) -
Going local not global Somehow, when learning LISP, you are
feeling bad when you define a bunch of global variable rather than the local ones. Example : (define (f x y) (let ((a 1) (b 2)) (+ (* x (square a)) (* y b) (* a b)))) Rather than : (define a 1) (define b 2) (define (f x y) (+ (* x (square a)) (* y b) (* a b))) -
Data Abstraction In OOP we have Class, Method, Variables, Interface,
Annotation, etc. And Object Oriented Concept such as Inheritance, Polymorphism, Encapsulation, etc. In LISP, i found the very simple yet clear concept about Data Abstraction and explained through this example : -
Arithmetic Operations in LISP (define (add-rat x y) (make-rat (+
(* (numer x) (denom y)) (* (numer y) (denom x))) (* (denom x) (denom y)))) (define (sub-rat x y) (make-rat (- (* (numer x) (denom y)) (* (numer y) (denom x))) (* (denom x) (denom y)))) (define (mul-rat x y) (make-rat (* (numer x) (numer y)) (* (denom x) (denom y)))) (define (div-rat x y) (make-rat (* (numer x) (denom y)) (* (denom x) (numer y)))) (define (equal-rat? x y) (= (* (numer x) (denom y)) (* (numer y) (denom x)))) (define (make-rat x y) (cons x y)) Consider a test case when x = 2/6, y = 4/8. What is the value of (add-rat x y) ? 2/6 + 4/8 = 8/24 + 12/24 = 20/24 Then.. -
2/6 + 4/8 = 8/24 + 12/24 = 20/24 To
make the equation simpler, we should divide the numerator and denumerator with GCD(20,24). We could implement divide-by-gcd for each of these function : add-rat, sub-rat, mul-rat, eq-rat but to make it simpler just implement divide-by-gcd on ‘make-rat’ function because the ‘make-rat’ function is a function which composing numerator and denumerator to be a single data. (define (make-rat x y) (let ((g (gcd x y)) (cons (/ x g) (/ y g))) Arithmetic Operations in LISP -
Bootstrapping Functional Programming Concept Enumerate - Filter - Map -
Accumulate Enumerate - Map - Filter - Accumulate In Functional Programming we always heard about HOF Term ( High Order Function ) which means abstracting your function as high as possible. (accumulate + (filter odd (map square (list 1 2 3 4 5)))) = 20 (accumulate + (map square (filter odd (list 1 2 3 4 5)))) = 20 -
Symbolic Data Consider this case : When someone told you
to ‘say your name aloud’, what would you do ? a. say your name : as example ‘BYAAN!’ b. say your name : as example ‘YOUR NAMEE!!’ On LISP, we could distinguish that a code which intended to be compiled or not to be compiled. Which means, we could control which code to be compiled and not to be compiled and it is awesome. -
LISP Advanced Topic 1. Macro 2. Object, State Modelling in
LISP 3. Concurrency 4. Building Metacircular Evaluator ( Meta Programming ) -
My Project on LISP Last Year at May 2015 I’ve
done my First LISP project and Last Project on my Campus. The project is about building a Recommendation System using an Algorithm called Regularization Kernel Matrix Factorization. But before, let’s talk about my Stack Development which are can’t be presented when i’m about to present it to my Lecturer * they are only concern with the Algorithm Analysis #boooooring * -
Online RKMF Recommender System LightTable as Editor Equipped with Leiningen.
SQL DSL for Clojure Ring/Clojure Routing Component on Clojure weavejester/hiccup HTML Templating on Clojure clojure.core.matrix matrix lib for Clojure -
Conclusion • LISP is a simple programming language for young
hacker/programmer/developer ( you mention it! ), because of it’s clarity guide into Abstraction and Programming Concept. ( young : someone with age < 100 and still alive! ) • LISP is a programming language based on Math ( besides Haskell ) and have a lot of feature that could be hacked or representing Math / AI problem related areas. -
Literature • SICP ( Structure Interpretation Computer Programming by MIT
Press ) • Clojure for the brave and true ( websites ) • Bill The Lizard ( Blog ) • The Joy Of Clojure ( Free - Ebook ) • On LISP ( Paul Graham - Book ) • Clojure-con / Infoq #Clojure