section 10 - lisp to scheme - vrije universiteit tjdhondt/esl/lisp_to_scheme_files/section 10 -...
Post on 02-May-2018
220 views
Embed Size (px)
TRANSCRIPT
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
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
http://www.independent.co.uk/news/obituaries/john-mccarthy-computer-scientist-known-as-the-father-of-ai-6255307.html
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
http://www.independent.co.uk/news/obituaries/john-mccarthy-computer-scientist-known-as-the-father-of-ai-6255307.html
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:
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
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
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
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
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
http://landoflisp.com/source.html
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)))))
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*)))))
Evolution of Software Languages 12
LISP example4
10: LISP to Scheme
(defun update-world () (setf *animals* (remove-if (lambda (animal) (
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))))))
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)
Evolution of Software Languages 15
The Actor Model1
10: LISP to Scheme
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))
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))
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))))