
Section 10: LISP to Scheme 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 Evolution of Software Languages 1 10: LISP to Scheme John McCarthy • Father of LISP • Credited with term "AI" • Built on the IBM 604/9 • Originated at MIT and at http://www.independent.co.uk/news/obituaries/ Stanford john-mccarthy-computer-scientist-known-as-the- father-of-ai-6255307.html • Survives in Common Lisp • Gave rise to Scheme • First "functional" language Evolution of Software Languages 2 10: LISP to Scheme John McCarthy Lispers say these are LISP... Arc, AutoLISP,• Father Clojure, of LISP Common Lisp, Emacs• Credited Lisp, EuLisp, with termFranz "AI" Lisp, Hy, Interlisp,• Built on ISLISP, the IBM LeLisp, 604/9 LFE, Maclisp,• Originated MDL, Newlisp, at MIT NIL, and at http://www.independent.co.uk/news/obituaries/ Stanford john-mccarthy-computer-scientist-known-as-the- father-of-ai-6255307.htmlPicolisp, Portable Standard Lisp, Racket, RPL,• Survives Scheme, in Common SKILL, Lisp Spice• Lisp,Gave T, rise Zetalisp to Scheme • First "functional" language Evolution of Software Languages 3 10: LISP to Scheme LISP I Programmer's Manual (March 1960) Define a function collapse: given some implementation for a function append: Evolution of Software Languages 4 10: LISP to Scheme LISP I Programmer's Manual (March 1960) Define a function collapse: resulting in the input card deck given some implementation for a function append: Evolution of Software Languages 5 10: LISP to Scheme (pre-) Common Lisp • 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 6 10: LISP to Scheme (pre-) Common Lisp • 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 7 10: LISP to Scheme (pre-) Common Lisp • 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 http://www.computerhistory.org/ revolution/artificial- • No tail call optimisation intelligence-robotics/13/290/1254 • No full continuations https://en.wikipedia.org/wiki/Symbolics Evolution of Software Languages 8 10: LISP to Scheme LISP example1 (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 Evolution of Software Languages 9 10: LISP to Scheme LISP example2 (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 10 10: LISP to Scheme LISP example3 (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 11 10: LISP to Scheme LISP example4 (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 "|")))) Evolution of Software Languages 12 10: LISP to Scheme LISP example5 (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 13 10: LISP to Scheme Carl Hewitt • Researcher at MIT • Built "Planner" • Defined "Actors" http://www.erlang-factory.com/sfbay2015/carl-hewitt • Hard to read papers • Fathered ACT-1, ... (Henry Lieberman) • (PhD with Seymour Papert) Evolution of Software Languages 14 10: LISP to Scheme The Actor Model1 Evolution of Software Languages 15 10: LISP to Scheme The Actor Model2 (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 16 10: LISP to Scheme The Actor Model2 (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 10: LISP to Scheme The Actor Model2 (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 10: LISP to Scheme The Actor Model2 (define p (act->scheme '((define counter (BEHAVIOR (value) (METHOD (up n) (list 'lambda empty (list '$new$ '$scheduler$ (list 'lambda (list 'ignore) (list 'define 'counter (list (list 'lambda empty (list 'define 'methods (BECOME (list counter'$make-dictionary$)) (+ value (list n))) '$put$ 'methods (list 'quote 'up) (list 'lambda ((listMETHOD 'self (down 'become! n) '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))))BECOME (list counter '$put$ 'methods (- value (list n)))'quote 'display) (list 'lambda (list 'self 'become! (METHOD 'value) (display)(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! (display 'tail 'arg-list) "value=") (list 'apply (list '$get$ 'methods 'msg) 'args)) 'dispatcher)))) (list 'define (display 'c1 (list '$make-actor$ value) 'counter 0)) (list 'define 'c2 (list '$make-actor$ 'counter 5)) (list '$new$ '$scheduler$ (list 'lambda (list 'ignore) (list '$switch$ '$scheduler$) (list 'c2 (list 'quote (newline)))) 'down) 2) (list '$exit$ '$scheduler$))) (list '$new$ '$scheduler$ (list 'lambda (list 'ignore) (list '$switch$ '$scheduler$) (list 'c1 (list 'quote 'up) 1) (list '$exit$ (define '$scheduler$))) c1 (NEW (list counter '$new$ '$scheduler$ 0)) (list 'lambda (list 'ignore) (list '$switch$ '$scheduler$) (list 'c2 (list 'quote 'up) 5) (list '$exit$ '$scheduler$))) (list '$new$ '$scheduler$ (list(define 'lambda c2 (list (NEW 'ignore) counter (list '$switch$5)) '$scheduler$) (list 'c1 (list 'quote 'display)) (list '$exit$ '$scheduler$))) (list '$new$ '$scheduler$ (list 'lambda (list 'ignore) (list
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages46 Page
-
File Size-