46
Evolution of Software Languages 1 Evolution of Software Languages Theo D'Hondt Bachelor of Computer Science Faculty of Sciences and Bio-Engineering Sciences Vrije Universiteit Brussel Academic Year 2015-2016 Section 10: LISP to Scheme 10: LISP to Scheme

Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Embed Size (px)

Citation preview

Page 1: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages 1

Evolution of

Software Languages

Theo D'Hondt

Bachelor of Computer Science Faculty of Sciences and Bio-Engineering Sciences

Vrije Universiteit Brussel Academic Year 2015-2016

Section 10: LISP to Scheme

10: LISP to Scheme

Page 2: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages 2

John McCarthy

10: LISP to Scheme

http://www.independent.co.uk/news/obituaries/john-mccarthy-computer-scientist-known-as-the-

father-of-ai-6255307.html

• Father of LISP • Credited with term "AI" • Built on the IBM 604/9 • Originated at MIT and at Stanford

• Survives in Common Lisp • Gave rise to Scheme • First "functional" language

Page 3: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages 3

John McCarthy

10: LISP to Scheme

http://www.independent.co.uk/news/obituaries/john-mccarthy-computer-scientist-known-as-the-

father-of-ai-6255307.html

• Father of LISP • Credited with term "AI" • Built on the IBM 604/9 • Originated at MIT and at Stanford

• Survives in Common Lisp • Gave rise to Scheme • First "functional" language

Lispers say these are LISP...

Arc, AutoLISP, Clojure, Common Lisp, Emacs Lisp, EuLisp, Franz

Lisp, Hy, Interlisp, ISLISP, LeLisp, LFE, Maclisp, MDL, Newlisp, NIL, Picolisp, Portable Standard Lisp,

Racket, RPL, Scheme, SKILL, Spice Lisp, T, Zetalisp

Page 4: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages 4

LISP I Programmer's Manual (March 1960)

10: LISP to Scheme

Define a function collapse:

given some implementation for a function append:

Page 5: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages 5

LISP I Programmer's Manual (March 1960)

10: LISP to Scheme

Define a function collapse:

given some implementation for a function append:

resulting in the input card deck

Page 6: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages 6

(pre-) Common Lisp

10: LISP to Scheme

• S-expressions • Functions as values • Meta-circularity • Quoting and eval • Automatic garbage collection • Full syntactic macros • (later) CLOS and MOP • Encourages imperative style • Ambivalent view on functions/function values • Ambivalent view on scoping • No tail call optimisation • No full continuations

Page 7: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages 7

(pre-) Common Lisp

10: LISP to Scheme

• S-expressions • Functions as values • Meta-circularity • Quoting and eval • Automatic garbage collection • Full syntactic macros • (later) CLOS and MOP • Encourages imperative style • Ambivalent view on functions/function values • Ambivalent view on scoping • No tail call optimisation • No full continuations

https://en.wikipedia.org/wiki/Symbolics

Page 8: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages 8

(pre-) Common Lisp

10: LISP to Scheme

• S-expressions • Functions as values • Meta-circularity • Quoting and eval • Automatic garbage collection • Full syntactic macros • (later) CLOS and MOP • Encourages imperative style • Ambivalent view on functions/function values • Ambivalent view on scoping • No tail call optimisation • No full continuations

https://en.wikipedia.org/wiki/Symbolics

http://www.computerhistory.org/revolution/artificial-

intelligence-robotics/13/290/1254

Page 9: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages 9

LISP example1

10: LISP to Scheme

(defparameter *width* 100) (defparameter *height* 30) (defparameter *jungle* '(45 10 10 10)) (defparameter *plant-energy* 80)

(defparameter *plants* (make-hash-table :test #'equal))

(defun random-plant (left top width height) (let ((pos (cons (+ left (random width)) (+ top (random height))))) (setf (gethash pos *plants*) t)))

(defun add-plants () (apply #'random-plant *jungle*) (random-plant 0 0 *width* *height*))

(defstruct animal x y energy dir genes)

(defparameter *animals* (list (make-animal :x (ash *width* -1) :y (ash *height* -1) :energy 1000 :dir 0 :genes (loop repeat 8 collecting (1+ (random 10))))))

http://landoflisp.com/source.html

Page 10: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages 10

LISP example2

10: LISP to Scheme

(defun move (animal) (let ((dir (animal-dir animal)) (x (animal-x animal)) (y (animal-y animal))) (setf (animal-x animal) (mod (+ x (cond ((and (>= dir 2) (< dir 5)) 1) ((or (= dir 1) (= dir 5)) 0) (t -1)) *width*) *width*)) (setf (animal-y animal) (mod (+ y (cond ((and (>= dir 0) (< dir 3)) -1) ((and (>= dir 4) (< dir 7)) 1) (t 0)) *height*) *height*)) (decf (animal-energy animal))))

(defun turn (animal) (let ((x (random (apply #'+ (animal-genes animal))))) (labels ((angle (genes x) (let ((xnu (- x (car genes)))) (if (< xnu 0) 0 (1+ (angle (cdr genes) xnu)))))) (setf (animal-dir animal) (mod (+ (animal-dir animal) (angle (animal-genes animal) x)) 8)))))

Page 11: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages 11

LISP example3

10: LISP to Scheme

(defun eat (animal) (let ((pos (cons (animal-x animal) (animal-y animal)))) (when (gethash pos *plants*) (incf (animal-energy animal) *plant-energy*) (remhash pos *plants*))))

(defparameter *reproduction-energy* 200)

(defun reproduce (animal) (let ((e (animal-energy animal))) (when (>= e *reproduction-energy*) (setf (animal-energy animal) (ash e -1)) (let ((animal-nu (copy-structure animal)) (genes (copy-list (animal-genes animal))) (mutation (random 8))) (setf (nth mutation genes) (max 1 (+ (nth mutation genes) (random 3) -1))) (setf (animal-genes animal-nu) genes) (push animal-nu *animals*)))))

Page 12: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages 12

LISP example4

10: LISP to Scheme

(defun update-world () (setf *animals* (remove-if (lambda (animal) (<= (animal-energy animal) 0)) *animals*)) (mapc (lambda (animal) (turn animal) (move animal) (eat animal) (reproduce animal)) *animals*) (add-plants))

(defun draw-world () (loop for y below *height* do (progn (fresh-line) (princ "|") (loop for x below *width* do (princ (cond ((some (lambda (animal) (and (= (animal-x animal) x) (= (animal-y animal) y))) *animals*) #\M) ((gethash (cons x y) *plants*) #\*) (t #\space)))) (princ "|"))))

Page 13: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages 13

LISP example5

10: LISP to Scheme

(defun evolution () (draw-world) (fresh-line) (let ((str (read-line))) (cond ((equal str "quit") ()) (t (let ((x (parse-integer str :junk-allowed t))) (if x (loop for i below x do (update-world) if (zerop (mod i 1000)) do (princ #\.)) (update-world)) (evolution))))))

Page 14: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages 14

Carl Hewitt

10: LISP to Scheme

http://www.erlang-factory.com/sfbay2015/carl-hewitt

• Researcher at MIT • Built "Planner" • Defined "Actors" • Hard to read papers • Fathered ACT-1, ... (Henry Lieberman)

• (PhD with Seymour Papert)

Page 15: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages 15

The Actor Model1

10: LISP to Scheme

Page 16: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages 16

The Actor Model2

10: LISP to Scheme

(define p (act->scheme '((define counter (BEHAVIOR (value) (METHOD (up n) (BECOME counter (+ value n))) (METHOD (down n) (BECOME counter (- value n))) (METHOD (display) (display "value=") (display value) (newline)))) (define c1 (NEW counter 0)) (define c2 (NEW counter 5)) (SEND c2 down 2) (SEND c1 up 1) (SEND c2 up 5) (SEND c1 display) (SEND c2 display)))) (define act-p (eval p (interaction-environment))) (act-p))

Page 17: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages 17

The Actor Model2

10: LISP to Scheme

(define p (act->scheme '((define counter (BEHAVIOR (value) (METHOD (up n) (BECOME counter (+ value n))) (METHOD (down n) (BECOME counter (- value n))) (METHOD (display) (display "value=") (display value) (newline)))) (define c1 (NEW counter 0)) (define c2 (NEW counter 5)) (SEND c2 down 2) (SEND c1 up 1) (SEND c2 up 5) (SEND c1 display) (SEND c2 display)))) (define act-p (eval p (interaction-environment))) (act-p))

Page 18: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages 18

The Actor Model2

10: LISP to Scheme

(define p (act->scheme '((define counter (BEHAVIOR (value) (METHOD (up n) (BECOME counter (+ value n))) (METHOD (down n) (BECOME counter (- value n))) (METHOD (display) (display "value=") (display value) (newline)))) (define c1 (NEW counter 0)) (define c2 (NEW counter 5)) (SEND c2 down 2) (SEND c1 up 1) (SEND c2 up 5) (SEND c1 display) (SEND c2 display)))) (define act-p (eval p (interaction-environment))) (act-p))

Page 19: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages 19

The Actor Model2

10: LISP to Scheme

(define p (act->scheme '((define counter (BEHAVIOR (value) (METHOD (up n) (BECOME counter (+ value n))) (METHOD (down n) (BECOME counter (- value n))) (METHOD (display) (display "value=") (display value) (newline)))) (define c1 (NEW counter 0)) (define c2 (NEW counter 5)) (SEND c2 down 2) (SEND c1 up 1) (SEND c2 up 5) (SEND c1 display) (SEND c2 display)))) (define act-p (eval p (interaction-environment))) (act-p))

(list 'lambda empty (list '$new$ '$scheduler$ (list 'lambda (list 'ignore) (list 'define 'counter (list (list 'lambda empty (list 'define 'methods (list '$make-dictionary$)) (list '$put$ 'methods (list 'quote 'up) (list 'lambda (list 'self 'become! 'value 'n) (list 'become! 'counter (list '+ 'value 'n)))) (list '$put$ 'methods (list 'quote 'down) (list 'lambda (list 'self 'become! 'value 'n) (list 'become! 'counter (list '- 'value 'n)))) (list '$put$ 'methods (list 'quote 'display) (list 'lambda (list 'self 'become! 'value) (list 'display "value=") (list 'display 'value) (list 'newline))) (list 'lambda (list 'args) (list 'define 'tail (list 'last 'args)) (list 'define (list 'dispatcher 'msg 'arg-list) (list 'set-cdr! 'tail 'arg-list) (list 'apply (list '$get$ 'methods 'msg) 'args)) 'dispatcher)))) (list 'define 'c1 (list '$make-actor$ 'counter 0)) (list 'define 'c2 (list '$make-actor$ 'counter 5)) (list '$new$ '$scheduler$ (list 'lambda (list 'ignore) (list '$switch$ '$scheduler$) (list 'c2 (list 'quote 'down) 2) (list '$exit$ '$scheduler$))) (list '$new$ '$scheduler$ (list 'lambda (list 'ignore) (list '$switch$ '$scheduler$) (list 'c1 (list 'quote 'up) 1) (list '$exit$ '$scheduler$))) (list '$new$ '$scheduler$ (list 'lambda (list 'ignore) (list '$switch$ '$scheduler$) (list 'c2 (list 'quote 'up) 5) (list '$exit$ '$scheduler$))) (list '$new$ '$scheduler$ (list 'lambda (list 'ignore) (list '$switch$ '$scheduler$) (list 'c1 (list 'quote 'display)) (list '$exit$ '$scheduler$))) (list '$new$ '$scheduler$ (list 'lambda (list 'ignore) (list '$switch$ '$scheduler$) (list 'c2 (list 'quote 'display)) (list '$exit$ '$scheduler$))) (list '$exit$ '$scheduler$))) (list '$start$ '$scheduler$))

Page 20: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages 20

The Actor Model2

10: LISP to Scheme

(define p (act->scheme '((define counter (BEHAVIOR (value) (METHOD (up n) (BECOME counter (+ value n))) (METHOD (down n) (BECOME counter (- value n))) (METHOD (display) (display "value=") (display value) (newline)))) (define c1 (NEW counter 0)) (define c2 (NEW counter 5)) (SEND c2 down 2) (SEND c1 up 1) (SEND c2 up 5) (SEND c1 display) (SEND c2 display)))) (define act-p (eval p (interaction-environment))) (act-p))

(list 'lambda empty (list '$new$ '$scheduler$ (list 'lambda (list 'ignore) (list 'define 'counter (list (list 'lambda empty (list 'define 'methods (list '$make-dictionary$)) (list '$put$ 'methods (list 'quote 'up) (list 'lambda (list 'self 'become! 'value 'n) (list 'become! 'counter (list '+ 'value 'n)))) (list '$put$ 'methods (list 'quote 'down) (list 'lambda (list 'self 'become! 'value 'n) (list 'become! 'counter (list '- 'value 'n)))) (list '$put$ 'methods (list 'quote 'display) (list 'lambda (list 'self 'become! 'value) (list 'display "value=") (list 'display 'value) (list 'newline))) (list 'lambda (list 'args) (list 'define 'tail (list 'last 'args)) (list 'define (list 'dispatcher 'msg 'arg-list) (list 'set-cdr! 'tail 'arg-list) (list 'apply (list '$get$ 'methods 'msg) 'args)) 'dispatcher)))) (list 'define 'c1 (list '$make-actor$ 'counter 0)) (list 'define 'c2 (list '$make-actor$ 'counter 5)) (list '$new$ '$scheduler$ (list 'lambda (list 'ignore) (list '$switch$ '$scheduler$) (list 'c2 (list 'quote 'down) 2) (list '$exit$ '$scheduler$))) (list '$new$ '$scheduler$ (list 'lambda (list 'ignore) (list '$switch$ '$scheduler$) (list 'c1 (list 'quote 'up) 1) (list '$exit$ '$scheduler$))) (list '$new$ '$scheduler$ (list 'lambda (list 'ignore) (list '$switch$ '$scheduler$) (list 'c2 (list 'quote 'up) 5) (list '$exit$ '$scheduler$))) (list '$new$ '$scheduler$ (list 'lambda (list 'ignore) (list '$switch$ '$scheduler$) (list 'c1 (list 'quote 'display)) (list '$exit$ '$scheduler$))) (list '$new$ '$scheduler$ (list 'lambda (list 'ignore) (list '$switch$ '$scheduler$) (list 'c2 (list 'quote 'display)) (list '$exit$ '$scheduler$))) (list '$exit$ '$scheduler$))) (list '$start$ '$scheduler$))

Welcome to DrScheme, version 372 [3m]. Language: Standard (R5RS) custom. started value=1 value=8 no more processes

Page 21: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages 21

The Actor Model3

10: LISP to Scheme

<program> ::= <expression>* <expression> ::= <scheme-expression> | <behavior-expression> | <become-expression> | <new-expression> | <send-expression> | <self-expression>

<behavior-expression> ::= (BEHAVIOR (<acquaintance>*) <method>*) <become-expression> ::= (BECOME <expression> <expression>*) <new-expression> ::= (NEW <expression> <expression>*) <send-expression> ::= (SEND <expression> <message> <expression>*) <self-expression> ::= SELF <scheme-expression> ::= scheme-expression

<method> ::= (METHOD (<message> <argument>*) <expression>*)

<acquaintance> ::= identifier <message> ::= identifier <argument> ::= identifier

Page 22: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages 22

The Actor Model4

10: LISP to Scheme

(define Factorial (BEHAVIOR () (METHOD (doit customer number) (BECOME Factorial) (display number) (newline) (if (= number 0) (SEND customer result 1) (let ((x (NEW FactCust customer number))) (SEND SELF doit x (- number 1)))))))

Page 23: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages 23

The Actor Model4

10: LISP to Scheme

(define Factorial (BEHAVIOR () (METHOD (doit customer number) (BECOME Factorial) (display number) (newline) (if (= number 0) (SEND customer result 1) (let ((x (NEW FactCust customer number))) (SEND SELF doit x (- number 1)))))))

(define FactCust (BEHAVIOR (customer number1) (METHOD (result number2) (SEND customer result (* number1 number2)))))

Page 24: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages 24

The Actor Model4

10: LISP to Scheme

(define Factorial (BEHAVIOR () (METHOD (doit customer number) (BECOME Factorial) (display number) (newline) (if (= number 0) (SEND customer result 1) (let ((x (NEW FactCust customer number))) (SEND SELF doit x (- number 1)))))))

(define FactCust (BEHAVIOR (customer number1) (METHOD (result number2) (SEND customer result (* number1 number2)))))

(define User (BEHAVIOR (fact) (METHOD (doit number) (SEND fact doit SELF number)) (METHOD (result number) (display (list "Value= " number)) (newline))))

Page 25: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages 25

The Actor Model4

10: LISP to Scheme

(define Factorial (BEHAVIOR () (METHOD (doit customer number) (BECOME Factorial) (display number) (newline) (if (= number 0) (SEND customer result 1) (let ((x (NEW FactCust customer number))) (SEND SELF doit x (- number 1)))))))

(define FactCust (BEHAVIOR (customer number1) (METHOD (result number2) (SEND customer result (* number1 number2)))))

(define User (BEHAVIOR (fact) (METHOD (doit number) (SEND fact doit SELF number)) (METHOD (result number) (display (list "Value= " number)) (newline))))

(define fact (NEW Factorial)) (SEND (NEW User fact) doit 10) (SEND (NEW User fact) doit 4)

Page 26: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages 26

The Actor Model5

10: LISP to Scheme

(define Fibonacci (BEHAVIOR (first second) (METHOD (fib customer number) (BECOME Fibonacci first second) (cond ((= number 0) (SEND customer result first)) ((= number 1) (SEND customer result second)) (else (let ((x (NEW FibCust customer))) (SEND SELF fib x (- number 1)) (SEND SELF fib x (- number 2))))))))

(define FibCust (BEHAVIOR (customer) (METHOD (result number) (BECOME FibCust2 customer number))))

(define FibCust2 (BEHAVIOR (customer number1) (METHOD (result number2) (SEND customer result (+ number1 number2)) (BECOME FibCust2 customer number1))))

(define User (BEHAVIOR (fibonacci) (METHOD (doit number) (BECOME User fibonacci) (SEND fibonacci fib (NEW Print) number))))

(define Print (BEHAVIOR () (METHOD (result number) (BECOME Print) (display "result=") (display number) (newline))))

(define fib (NEW Fibonacci 1 1)) (SEND (NEW User fib) doit 6) (SEND (NEW User fib) doit 4)

Page 27: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages 27

The Actor Model6

10: LISP to Scheme

• Very high-level view on concurrency • Most famous offshoot: Erlang • Basis for process calculi • Imperative (see BECOME) • Asynchronous • No (evident) global state • Inherently concurrent • (Unbounded) non deterministic

Page 28: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages 28

Guy Steele - Gerald Sussman

10: LISP to Scheme

https://en.wikipedia.org/wiki/Guy_L._Steele,_Jr.

http://cunydhi.commons.gc.cuny.edu/2015/03/21/should-we-fear-intelligent-machines/

• Researchers at MIT • Built "Scheme" ←Common Lisp →SICP →PhD with Seymour

Papert ←PhD with →

Page 29: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages 29

The case of Scheme

10: LISP to Scheme

from AIM-848

Page 30: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages 30

Scheme and Actors

10: LISP to Scheme

Sussman and Steele December 22 1875 48 leeentatlon of the in ter r e t e r

Acknowledgements

This work developed out of an initial attempt to understand the .

This paper would not have happened if Sussman had not been forced tothink about lambda calculus by having to teach 6,031, nor would it havehappened had not Steele been forced to understand PLASNA by morbid curiosity.

actorness of actors. Steele thought he understood it, but couldn't explainit; Sussman suggested the experimental approach of actually building an"ACTORS interpreter". This interpreter attempted to intermix the use ofactors and LISP lambda expressions in a clean manner. When it was completed,we discovered that the "actors" and the lambda expressions were identical inimplementation. Once we had discovered this, all the rest fell into place,and it was only natural to begin thinking about actors in terms of lambdacalculus. The original interpreter was call-by-name for various reasonshaving to do with 6.031; we subsequently experimentally discovered how call-by-name screws iteration, and rewrote it to use call-by-value. Note well that,we did not bring forth a clean implementation in one brilliant flash ofunderstanding; we used an experimental and highly empirical approach tobootstrap our knowledge.

precipitating this intellectual adventure. Carl Hewitt spent many hoursexplaining the innards and outards of PLASI'IA to Steele over the course ofseveral months; Narilyn McClennan was also helpf'ul in this respect. BrianSmith and Richard Zippel helped a lot. We wish to thank Seymour Papert, BenKuipers, Narvin Ninsky, and Vaughn Pratt for their excellent suggestions.

We wish to thank the staff of 6.031, Nike Dertouzos, and Steve Ward, for

from AIM-349

Page 31: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages 31

A timeline for Scheme1

10: LISP to Scheme

43pp

35pp

76pp

Page 32: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages 32

A timeline for Scheme2

10: LISP to Scheme

2007

DRAFT

1991

1986

1998

+ IEEE Standard 1178-1990

43pp

55pp

90pp

50pp

88pp

Page 33: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages 33

Semantics for Scheme1

10: LISP to Scheme

AIM-349

AIM-848 (RRRS)

AIM-452

R3RS

R4RS

R5RS

R6RS

R7RS

informal lambda-calculus substitution semantics

informal

... a formal definition of the semantics of Scheme will be included in a separate report ...

denotational semantics + rewrite rules

denotational semantics + rewrite rules + macros (added support for immutables)

denotational semantics + syntactic forms

operational semantics

denotational semantics + syntactic forms (added support for dynamic-wind)

Page 34: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages 34

Semantics for Scheme2

10: LISP to Scheme

Pa

ge

33

fro

m R

3R

S

Page 35: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages 35

e.g. argument evaluation

10: LISP to Scheme

I

value when considered as an identifier.

. may be lexically bound by lambda-expressions. There is a global environmentcontai.ning values for (some} free variables. Nany of the variables in thisglobal environment initially have as their values primitive operations suchas, for example, cAR, coMs, and pLUs. SCHENE dif'fers from most LISP systems int hat t h e atom cat iS not itself an operation (in the sense of b e i n g a ninvocable object, e.g. a valid first argument to AvvLY), but only has one as a

Non-atomic forms are divided by the evaluator into two classes:combinations and "magic (special) forms". T he BNF given above i s ambiguous;any magic form c an also be p a r se d a s a combination. The e valuator a l w a y st reats an ambiguous case 'as a magic form. Nagic forms are recognized by thepresence of a "magic (reserved) word" in the car position of the form. Allnon-atomic forms which are not magic forms are considered to be combinations.The system has a small initial set of magic words; there is also a mechanismfor creating new ones (Note FUMCALL is a Pain).

are all evaluated. The first value must be a procedure; it is applied to theother values to get the value of the combination. There are four importantp oints he re :

(I) T he procedure p o s i t i o n is always evaluated just l ike an y o t he rposit ion . (This is why the primitive operators are . the v a l u e s o f globa lidentifiers.)

( <) The procedure is never " re -evaluated"; if the first subfoi m fails toe valuate t o an applicable procedure, it is an error . Thu s , u n l i k e mostLISP systems, SCHENE always evaluates the first subform of a combinationexactly once .

(3) The arguments are all completely evaluated before the procedure isapplied; that is, SCHENE, like most LISP systems, is an applicative-orderlanguage. Nany SCHENE programs exploit this fact.

(4) The argument forms (and procedure f'orm) may in principle be evaluatedi n any o r d e r . This is unlike the usual LISP left-to-right order . (AllSCHEI'lE interpreters implemented so far have in fact performed left-to-rightevaluation, but we do not wish programs to depend on this fact. Indeed,the~e are some reasons why a clever interpreter might want to evaluate themright-to-left, e.g. to get things on a stack in the correct order.}

A combination is considered to be a list of subforms. These subforms

AIM-452

AIM-848

The Revised Revised Report on Scheme

(operator operandf . . . ) essential special formA list whose first element is not the keyword of a special form indicates a

procedure eall. The operator and operand expressions are evaluated and the

resulting procedure is passed the resulting arguments. In contrast to otherdialects of Lisp the order of evaluation is not specified, and the operatorexpression and the operand expressions are always evaluated with the same

evaluation rules.

(+ 3 4)( (11.' 0!false + +) 3 4 )

(quote datum) essential special formdatum essential special form

Evaluates to datum. This notation is used to include literal constants inScheme code.

(quote a)(quote 0(a b c ) )(quote (+ 1 2 ) )

a.4(a b c)(+ 1 2)

(quote datum) may be abbreviated as 'datum. The two notations are equiv-alent in all respects.

'a'4(a b c)'(+ 1 2)'(quote a)

C(a b c)(+ 1 2)(quote a)(quote a)

Numeric constants, string constants, character constants, vect;or constants,and the constants 0! t rue , 0 ! f a l s e , and 0 ! nu l l n e e d no t be qu o t ed .

> IIgb(. IIII abC'146932146932'0!truet !t rue

II gb( II

II gb(. II

1459321469320!true0!true

(lambda (earl .. .) ezpr) essential special formEach ear must be an identifier. The lambda expression evaluates to a pro-

cedure with formal argument list (uar1 ... ) and procedure body ezpr Th e .environment in effect when the lambda expression was evaluated is rernem-bered as part of the procedure. When the procedure is later called with some

ℇ ⟦(E0 E*)⟧ = λρκ . ℇ*(permute (⟨E0⟩ § E*)) ρ (λε* . ((λε* . applicate (ε* ↓ 1) (ε* † 1) κ) (unpermute ε*)))

R3RS →R7RS \ R6RS

The order of evaluation within a call is unspecified. We mimic that here by applying arbitrary permutations permute and unpermute, which must be inverses, to the arguments in a call before and after they are evaluated. This {still requires | is not quite right since it suggests, incorrectly, } that the order of evaluation is constant throughout a program (for any given number of arguments), but it is a closer approximation to the intended semantics than a left-to-right evaluation would be.

Page 36: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages 36

Glitches1

10: LISP to Scheme

Welcome to DrScheme, version 372 [3m]. Language: Standard (R5RS) custom. > (define (f) '(1 . 2)) > (define z (f)) > (set-car! z 3) > z (cons 3 2) > (f) (cons 3 2) >

Page 37: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages37

Glitches2

10: LISP to Scheme

Welcome to DrScheme, version 372 [3m]. Language: Standard (R5RS) custom. > (define (f) (define x 1) (define y x) y) > (f) 1

Page 38: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages38

Glitches2

10: LISP to Scheme

Welcome to DrScheme, version 372 [3m]. Language: Standard (R5RS) custom. > (define (f) (define x 1) (define y x) y) > (f) 1

Welcome to DrScheme, version 6.0 [3m]. Language: Standard (R5RS) custom. > (define (f) (define x 1) (define y x) y) > (f) #<undefined>

Page 39: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages39

Glitches2

10: LISP to Scheme

Welcome to DrScheme, version 372 [3m]. Language: Standard (R5RS) custom. > (define (f) (define x 1) (define y x) y) > (f) 1

Welcome to DrScheme, version 6.0 [3m]. Language: Standard (R5RS) custom. > (define (f) (define x 1) (define y x) y) > (f) #<undefined>

Welcome to DrScheme, version 6.0 [3m]. Language: Standard (R5RS) custom. > (define (f) (define x 1) (define y x) y) > (f) 1

Page 40: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages40

Showcase: metacircularity1

10: LISP to Scheme

(define circularity-level 0) ; only 1st time

(begin (define old-circularity-level circularity-level) (define circularity-level (+ old-circularity-level 1)) (define meta-level-eval eval) (define eval '()) (define environment '()) (define (loop output) (define rollback environment) (define (evaluate expression) ... )

(display output) (newline) (display "level") (display circularity-level) (display ">") (set! eval evaluate) (loop (evaluate (read))))

(loop "Lisp in 100 lines"))

Page 41: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages41

Showcase: metacircularity2

10: LISP to Scheme

Welcome to DrScheme, version 372 [3m]. Language: Standard (R5RS) custom. Lisp in 100 lines level:1>(begin (define old-circularity-level circularity-level) (define circularity-level (+ old-circularity-level 1)) (define meta-level-eval eval) (define eval '()) (define environment '()) (define (loop output)

...

Lisp in 100 lines level:4>(+ 1 2) 3

this is where I feed the interpreter 3x to itself

Page 42: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages42

Showcase: metacircularity3

10: LISP to Scheme

(define (evaluate expression) (define (error message qualifier) (display message) (set! environment rollback) (loop qualifier)) ; functions (define (bind-variable variable value) ... (define (bind-parameters parameters arguments) ... (define (evaluate-sequence expressions) ... (define (make-procedure parameters expressions) ... ; evaluation functions ... (if (symbol? expression) (evaluate-variable expression) (if (pair? expression) ...

expression)))

Page 43: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages43

Showcase: metacircularity3

10: LISP to Scheme

(define (evaluate expression) (define (error message qualifier) (display message) (set! environment rollback) (loop qualifier)) ; functions (define (bind-variable variable value) ... (define (bind-parameters parameters arguments) ... (define (evaluate-sequence expressions) ... (define (make-procedure parameters expressions) ... ; evaluation functions ... (if (symbol? expression) (evaluate-variable expression) (if (pair? expression) ...

expression)))

(if (symbol? expression) (evaluate-variable expression) (if (pair? expression) (apply (if (equal? (car expression) 'begin) evaluate-begin (if (equal? (car expression) 'define) evaluate-define (if (equal? (car expression) 'if) evaluate-if (if (equal? (car expression) 'lambda) evaluate-lambda (if (equal? (car expression) 'quote) evaluate-quote (if (equal? (car expression) 'set!) evaluate-set! (evaluate-application (car expression)))))))) (cdr expression)) expression)))

Page 44: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages44

Showcase: metacircularity3

10: LISP to Scheme

(define (evaluate expression) (define (error message qualifier) (display message) (set! environment rollback) (loop qualifier)) ; functions (define (bind-variable variable value) ... (define (bind-parameters parameters arguments) ... (define (evaluate-sequence expressions) ... (define (make-procedure parameters expressions) ... ; evaluation functions ... (if (symbol? expression) (evaluate-variable expression) (if (pair? expression) ...

expression)))

(define (make-procedure parameters expressions) (define lexical-environment environment) (define procedure '()) (lambda arguments (define dynamic-environment environment) (set! environment lexical-environment) (bind-parameters parameters arguments) (begin (set! procedure (evaluate-sequence expressions)) (set! environment dynamic-environment) procedure)))

Page 45: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages 45

Conclusion

10: LISP to Scheme

• Arguably the most expressive programming language

• Also the first grounded programming language

• Source of inspiration for many other languages

• The start of functional programming

• The start of language semantics

• The start of metaprogramming and reflection

• The starting platform for AI

• Continues with Common Lisp as a commercially viable platform

• And also so many things more ...

Page 46: Section 10 - LISP to Scheme - Vrije Universiteit Brusselsoft.vub.ac.be/~tjdhondt/ESL/LISP_to_Scheme_files/Section 10 - LISP...Section 10: LISP to Scheme 10: LISP to Scheme. Evolution

Evolution of Software Languages 46

Assignment

10: LISP to Scheme

1. Construct an unbounded queue in the actor model

2. Make Lisp-in-100-lines run in Racket

3. Translate it into (a) Lisp