A few words about me
 Name: Nikolay Mozgovoy
 Developer in Sigma Software since 2013
and mentor since 2016
 Teacher in KhAI (Department Of Computer
Systems, Networks And Cybersecurity)
 GGJ Ukraine prizewinner (2016, 2017)
 GGJ Site organizer (Kharkiv)
 MSCSD: App builder
 Caught Lisp
LISP:
Back to the future
(A tribute to 60th anniversary)
Long term languages trends (TIOBE)
LANGUAGE 2018 2013 2008 2003 1998 1993 1988
Java 1 2 1 1 15 - -
C 2 1 2 2 1 1 1
C++ 3 4 3 3 2 2 5
Python 4 7 6 12 23 18 -
C# 5 5 7 8 - - -
Javascript 7 10 8 7 19 - -
Perl 11 8 5 4 3 12
LISP 31 11 15 13 8 4 3
Why language matter?
It is practically impossible to teach good
programming to students that have had a prior
exposure to BASIC: as potential programmers
they are mentally mutilated beyond hope of
regeneration.
Edsger Wybe Dijkstra
Why language matter?
Computer programs are all just text. And the
language you choose determines what you can
say.
Programming languages are what
programmers think in.
Paul Graham
John McCarthy
In 1960, John McCarthy published a
remarkable paper in which he did for
programming something like what Euclid did
for geometry. He showed how, given a handful
of simple operators and a notation for
functions, you can build a whole programming
language
Paul Graham
LISP Origins
A programming system called LISP (List
Processor) has been developed for the IBM
704 computer by the Artificial Intelligence
group at M.I.T. The system was designed to
facilitate experiments with a proposed system
called the Advice Taker, whereby a machine
could be instructed to handle declarative as
well as imperative sentences and could exhibit
“common sense” in carrying out its instructions.
John McCarthy
Original LISP Syntax
 S-Expressions (for “symbolic expression”): ( · ) + an infinite set of atomic symbols:
AB
(A · B)
((AB · C) · D)
(A·((B ·(C · NIL)) ·(D · NIL)))
 M-Expressions:
car[x]
car[cons[(A · B);x]]
 cons (“construct”)
 car (“contents of address register”)
 cdr (“contents of decrement register”)
LISP VS Fortran/Algol ancestor
var animals = new[] { "dog", "cat", "rat" };
void PrintAnimals()
{
foreach (var animal in animals)
{
Console.WriteLine(animal);
}
}
PrintAnimals();
#lang racket
(define animals (list "dog" "cat" "rat"))
(define (print-animals x) (map print animals))
(print-animals)
LISP Innovations
 IF Statement
 Garbage collection
 Function as a first-class datatype
 Lambda-expressions
 Functional programming
 Homoiconic syntax + eval
 Metaprogramming
 Continuations
 Multiple dynamic dispatch (aka Multimethods)
 Recursion
 Lisp machines (HLLCA)
Primary dialects
 Scheme (1970)
 Common LISP (1984)
 Clojure (2007)
Metaprogramming
(defn pow2 [x] (* x x))
(defn inc [x] (+ x 1))
(def strategy (read-string "[pow2 inc inc]")) ; user input
(def input (read-string "12")) ; user input
((apply comp (eval strategy)) input) ; 196
Metaprogramming (2)
(defn drive-to-home [] "driving to home")
(defn drive-to-work [] "driving to work")
(defn drive-to-garage [] "driving to garage")
(defn recharge [] "recharging")
(defn get-driving-program []
`(drive-to-home drive-to-work recharge drive-to-garage))
(map #(println (%))
(map eval (get-driving-program)))
Macros: definition
#lang racket
(define-syntax (show-this stx)
(print stx)
(syntax(void)))
;#<syntax:3:2 (show-this (quote (+ 1 2)))>
A macros is a syntactic form with an
associated transformer that expands
the original form into existing forms.
To put it another way, a macro is an
extension to the LISP compiler.
Using macro you can create:
 New language features
 DSL
Macros: creating missing constructs
;while macros application
(define x 10)
(while (> x 0) do
(displayln x)
(set! x (- x 1)))
; prints 10, 9, 8 , 7, 6, 5, 4, 3, 2, 1
;while macros definition
(define-syntax while
(syntax-rules (do)
[(while cond do body ...)
(let loop ()
(when cond body ...
(loop)))]))
Macros: changing evaluation strategy
;while macros application
(take 5 Nat)
; '(1 . #<promise:...0>)
(!! (take 5 Nat))
;'(1 2 3 4 5)
#lang lazy
;sequence: a_(n+1) = f(a_n)
(define inf-seq
(lambda (a0 f)
(cons a0 (inf-seq (f a0) f))))
(define natural
(inf-seq 1 (lambda (x) (+ x 1))))
Macros: changing type system
;This code will fail to compile
;Type Checker: type mismatch
expected: Integer
(define test (λ () (factorial 7.5)))
#lang typed/racket
(: factorial : Integer -> Integer)
(define (factorial n)
(if (<= n 0)
1
(* n (factorial (- n 1)))))
Macros: getting rid of parentheses (t-expressions)
#lang sweet-exp typed/racket
define: factorial([n : Integer]) : Integer
if {n <= 1}
1
{n * factorial{n - 1}}
factorial 5 ;- : Integer 120
#lang sweet-exp racket
define factorial(n)
if {n <= 1}
1
{n * factorial{n - 1}}
factorial 5 ;120
Continuations
(define (f return)
(return 2)
3)
(display (f (lambda (x) x)))
; displays 3
(display (call-with-current-continuation f))
; displays 2
Continuation is an abstract
representation of the control state of a
computer program
The "current continuation" is the
continuation that, from the
perspective of running code, would be
derived from the current point in a
program's execution
Continuations (2)
(test) ; 1
(the-continuation) ; 2
(the-continuation) ; 3
; store the current continuation
; (which will print 4 next) away
(define another-continuation the-continuation)
; reset the-continuation
(test) ; 1
(the-continuation) ; 2
; use the previously stored continuation
(another-continuation) ; 4
(define the-continuation #f)
(define (test)
(let ((i 0))
; call/cc calls its first function argument, passing
; a continuation variable representing this point in
; the program as the argument to that function.
; In this case, the function argument assigns that
; continuation to the variable the-continuation.
(call/cc (lambda (k) (set! the-continuation k)))
; The next time the-continuation is called, we start here.
(set! i (+ i 1))
i))
Multiple dynamic dispatch
(require multimethod)
(struct asteroid ())
(struct space-ship ())
(define-generic (collide a b))
(define-instance (
(collide asteroid space-ship) a b)
(println "Asteroid collided with the space ship"))
(define-instance (
(collide space-ship asteroid) a b)
(println "Space ship collided with the asteroid"))
Multimethods are functions that can
have many different implementations
depending on the types of arguments
they are invoked on. For example, a
generic add function might have
different implementations for adding
scalars and vectors.
Projects implemented in LISP
 EMACS
 Autodesk (3D creation and editing suite)
 Mirai (3D creation and editing suite)
 Maxima (computer algebra system)
 Viaweb (Yahoo Store)
 ITA Software (Google Flights)
 NASA Deep Space 1
 https://franz.com/success/
Rich Hickey & Clojure
We should aim for simplicity because simplicity
is a prerequisite for reliability.
The benefits of simplicity are: ease of
understanding, ease of change, ease of
debugging, flexibility.
Rich Hickey from Simple Made Easy
Full Clojure Stack
LISP Quotes
In a Lisp program, you can write a program
that writes Lisp programs so it has a kind of
open future; now, no… no-one actually does
that yet, but it’s still possible. In the other
languages, it's almost… you can’t write a C
program that will write a C program, it’s just…
there aren’t any verbs of the right kind, so to
me programming hasn’t changed much in 50
years because they got locked into this…
strange set of limitations.
Marvin Minsky
LISP Quotes
The most powerful programming language is
Lisp. If you don't know Lisp (or its variant,
Scheme), you don't appreciate what a powerful
language is. Once you learn Lisp you will see
what is missing in most other languages.
Richard Stallman
LISP Quotes
OOP to me means only messaging, local
retention and protection and hiding of state-
process, and extreme late-binding of all things.
It can be done in Smalltalk and in LISP.
LISP is the greatest single programming
language ever designed, the most important
idea in computer science.
Alan Kay
LISP Quotes
LISP has been jokingly described as "the most
intelligent way to misuse a computer". I think
that description a great compliment because it
transmits the full flavor of liberation: it has
assisted a number of our most gifted fellow
humans in thinking previously impossible
thoughts.
Edsger Wybe Dijkstra
If Lisp is so great, why it is unpopular?
 There were too many dialects
 LISP was too demanding for mainstream hardware in the ’70s
 In languages, as in so many things, there's not much correlation between
popularity and quality
 Languages are not merely technologies, but habits of mind as well, and
nothing changes slower
Resources
 Structure and interpretation of computer programs
 http://web.mit.edu/alexmv/6.037/sicp.pdf
 Hackers and painters
 Google Play Books
 Amazon
 Realm of Racket
 http://www.realmofracket.com/
 Living Сlojure
 Oreilly
 Practical Common Lisp
 http://www.gigamonkeys.com/book/

LISP: назад в будущее, Микола Мозговий

  • 2.
    A few wordsabout me  Name: Nikolay Mozgovoy  Developer in Sigma Software since 2013 and mentor since 2016  Teacher in KhAI (Department Of Computer Systems, Networks And Cybersecurity)  GGJ Ukraine prizewinner (2016, 2017)  GGJ Site organizer (Kharkiv)  MSCSD: App builder  Caught Lisp
  • 3.
    LISP: Back to thefuture (A tribute to 60th anniversary)
  • 4.
    Long term languagestrends (TIOBE) LANGUAGE 2018 2013 2008 2003 1998 1993 1988 Java 1 2 1 1 15 - - C 2 1 2 2 1 1 1 C++ 3 4 3 3 2 2 5 Python 4 7 6 12 23 18 - C# 5 5 7 8 - - - Javascript 7 10 8 7 19 - - Perl 11 8 5 4 3 12 LISP 31 11 15 13 8 4 3
  • 5.
    Why language matter? Itis practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. Edsger Wybe Dijkstra
  • 6.
    Why language matter? Computerprograms are all just text. And the language you choose determines what you can say. Programming languages are what programmers think in. Paul Graham
  • 7.
    John McCarthy In 1960,John McCarthy published a remarkable paper in which he did for programming something like what Euclid did for geometry. He showed how, given a handful of simple operators and a notation for functions, you can build a whole programming language Paul Graham
  • 8.
    LISP Origins A programmingsystem called LISP (List Processor) has been developed for the IBM 704 computer by the Artificial Intelligence group at M.I.T. The system was designed to facilitate experiments with a proposed system called the Advice Taker, whereby a machine could be instructed to handle declarative as well as imperative sentences and could exhibit “common sense” in carrying out its instructions. John McCarthy
  • 9.
    Original LISP Syntax S-Expressions (for “symbolic expression”): ( · ) + an infinite set of atomic symbols: AB (A · B) ((AB · C) · D) (A·((B ·(C · NIL)) ·(D · NIL)))  M-Expressions: car[x] car[cons[(A · B);x]]  cons (“construct”)  car (“contents of address register”)  cdr (“contents of decrement register”)
  • 10.
    LISP VS Fortran/Algolancestor var animals = new[] { "dog", "cat", "rat" }; void PrintAnimals() { foreach (var animal in animals) { Console.WriteLine(animal); } } PrintAnimals(); #lang racket (define animals (list "dog" "cat" "rat")) (define (print-animals x) (map print animals)) (print-animals)
  • 11.
    LISP Innovations  IFStatement  Garbage collection  Function as a first-class datatype  Lambda-expressions  Functional programming  Homoiconic syntax + eval  Metaprogramming  Continuations  Multiple dynamic dispatch (aka Multimethods)  Recursion  Lisp machines (HLLCA)
  • 12.
    Primary dialects  Scheme(1970)  Common LISP (1984)  Clojure (2007)
  • 13.
    Metaprogramming (defn pow2 [x](* x x)) (defn inc [x] (+ x 1)) (def strategy (read-string "[pow2 inc inc]")) ; user input (def input (read-string "12")) ; user input ((apply comp (eval strategy)) input) ; 196
  • 14.
    Metaprogramming (2) (defn drive-to-home[] "driving to home") (defn drive-to-work [] "driving to work") (defn drive-to-garage [] "driving to garage") (defn recharge [] "recharging") (defn get-driving-program [] `(drive-to-home drive-to-work recharge drive-to-garage)) (map #(println (%)) (map eval (get-driving-program)))
  • 15.
    Macros: definition #lang racket (define-syntax(show-this stx) (print stx) (syntax(void))) ;#<syntax:3:2 (show-this (quote (+ 1 2)))> A macros is a syntactic form with an associated transformer that expands the original form into existing forms. To put it another way, a macro is an extension to the LISP compiler. Using macro you can create:  New language features  DSL
  • 16.
    Macros: creating missingconstructs ;while macros application (define x 10) (while (> x 0) do (displayln x) (set! x (- x 1))) ; prints 10, 9, 8 , 7, 6, 5, 4, 3, 2, 1 ;while macros definition (define-syntax while (syntax-rules (do) [(while cond do body ...) (let loop () (when cond body ... (loop)))]))
  • 17.
    Macros: changing evaluationstrategy ;while macros application (take 5 Nat) ; '(1 . #<promise:...0>) (!! (take 5 Nat)) ;'(1 2 3 4 5) #lang lazy ;sequence: a_(n+1) = f(a_n) (define inf-seq (lambda (a0 f) (cons a0 (inf-seq (f a0) f)))) (define natural (inf-seq 1 (lambda (x) (+ x 1))))
  • 18.
    Macros: changing typesystem ;This code will fail to compile ;Type Checker: type mismatch expected: Integer (define test (λ () (factorial 7.5))) #lang typed/racket (: factorial : Integer -> Integer) (define (factorial n) (if (<= n 0) 1 (* n (factorial (- n 1)))))
  • 19.
    Macros: getting ridof parentheses (t-expressions) #lang sweet-exp typed/racket define: factorial([n : Integer]) : Integer if {n <= 1} 1 {n * factorial{n - 1}} factorial 5 ;- : Integer 120 #lang sweet-exp racket define factorial(n) if {n <= 1} 1 {n * factorial{n - 1}} factorial 5 ;120
  • 20.
    Continuations (define (f return) (return2) 3) (display (f (lambda (x) x))) ; displays 3 (display (call-with-current-continuation f)) ; displays 2 Continuation is an abstract representation of the control state of a computer program The "current continuation" is the continuation that, from the perspective of running code, would be derived from the current point in a program's execution
  • 21.
    Continuations (2) (test) ;1 (the-continuation) ; 2 (the-continuation) ; 3 ; store the current continuation ; (which will print 4 next) away (define another-continuation the-continuation) ; reset the-continuation (test) ; 1 (the-continuation) ; 2 ; use the previously stored continuation (another-continuation) ; 4 (define the-continuation #f) (define (test) (let ((i 0)) ; call/cc calls its first function argument, passing ; a continuation variable representing this point in ; the program as the argument to that function. ; In this case, the function argument assigns that ; continuation to the variable the-continuation. (call/cc (lambda (k) (set! the-continuation k))) ; The next time the-continuation is called, we start here. (set! i (+ i 1)) i))
  • 22.
    Multiple dynamic dispatch (requiremultimethod) (struct asteroid ()) (struct space-ship ()) (define-generic (collide a b)) (define-instance ( (collide asteroid space-ship) a b) (println "Asteroid collided with the space ship")) (define-instance ( (collide space-ship asteroid) a b) (println "Space ship collided with the asteroid")) Multimethods are functions that can have many different implementations depending on the types of arguments they are invoked on. For example, a generic add function might have different implementations for adding scalars and vectors.
  • 23.
    Projects implemented inLISP  EMACS  Autodesk (3D creation and editing suite)  Mirai (3D creation and editing suite)  Maxima (computer algebra system)  Viaweb (Yahoo Store)  ITA Software (Google Flights)  NASA Deep Space 1  https://franz.com/success/
  • 24.
    Rich Hickey &Clojure We should aim for simplicity because simplicity is a prerequisite for reliability. The benefits of simplicity are: ease of understanding, ease of change, ease of debugging, flexibility. Rich Hickey from Simple Made Easy
  • 25.
  • 26.
    LISP Quotes In aLisp program, you can write a program that writes Lisp programs so it has a kind of open future; now, no… no-one actually does that yet, but it’s still possible. In the other languages, it's almost… you can’t write a C program that will write a C program, it’s just… there aren’t any verbs of the right kind, so to me programming hasn’t changed much in 50 years because they got locked into this… strange set of limitations. Marvin Minsky
  • 27.
    LISP Quotes The mostpowerful programming language is Lisp. If you don't know Lisp (or its variant, Scheme), you don't appreciate what a powerful language is. Once you learn Lisp you will see what is missing in most other languages. Richard Stallman
  • 28.
    LISP Quotes OOP tome means only messaging, local retention and protection and hiding of state- process, and extreme late-binding of all things. It can be done in Smalltalk and in LISP. LISP is the greatest single programming language ever designed, the most important idea in computer science. Alan Kay
  • 29.
    LISP Quotes LISP hasbeen jokingly described as "the most intelligent way to misuse a computer". I think that description a great compliment because it transmits the full flavor of liberation: it has assisted a number of our most gifted fellow humans in thinking previously impossible thoughts. Edsger Wybe Dijkstra
  • 30.
    If Lisp isso great, why it is unpopular?  There were too many dialects  LISP was too demanding for mainstream hardware in the ’70s  In languages, as in so many things, there's not much correlation between popularity and quality  Languages are not merely technologies, but habits of mind as well, and nothing changes slower
  • 31.
    Resources  Structure andinterpretation of computer programs  http://web.mit.edu/alexmv/6.037/sicp.pdf  Hackers and painters  Google Play Books  Amazon  Realm of Racket  http://www.realmofracket.com/  Living Сlojure  Oreilly  Practical Common Lisp  http://www.gigamonkeys.com/book/

Editor's Notes

  • #6 What's wrong with VB and similar languages? I think they do not promote wishful thinking.
  • #9 John McCarthy is famous as AI pioneer. (AI term itself belongs to him) The mentioned article is Recursive Functions of Symbolic Expressions and Their Computation by Machine, Part I
  • #11 S-Expressions are AST itself
  • #18 while statement is missing by default
  • #19 Lisp/Racket uses Eager evaluation by default, but connection of the lazy module swathes it to Lazy
  • #20 LISP/Scheme/Racket are dynamically typed languages, but you can change it
  • #21 Combining different langusages
  • #31 What's wrong with VB and similar languages? I think they do not promote wishful thinking.