2. 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
5. 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
6. 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
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 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
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”)
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 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)))]))
18. 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)))))
20. 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
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
(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.
23. 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/
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
26. 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
27. 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
28. 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
29. 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
30. 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
31. 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/
Editor's Notes
What's wrong with VB and similar languages?
I think they do not promote wishful thinking.
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
S-Expressions are AST itself
while statement is missing by default
Lisp/Racket uses Eager evaluation by default, but connection of the lazy module swathes it to Lazy
LISP/Scheme/Racket are dynamically typed languages, but you can change it
Combining different langusages
What's wrong with VB and similar languages?
I think they do not promote wishful thinking.