Section 10: LISP to Scheme. Evolution of Software Languages

Similar documents
Functional Programming with Common Lisp

CS 314 Principles of Programming Languages

INF4820: Algorithms for Artificial Intelligence and Natural Language Processing. Common Lisp Fundamentals

Functional Programming. Pure Functional Languages

Functional Programming. Pure Functional Languages

Organization of Programming Languages CS3200/5200N. Lecture 11

FUNKCIONÁLNÍ A LOGICKÉ PROGRAMOVÁNÍ 2. ÚVOD DO LISPU: ATOMY, SEZNAMY, FUNKCE,

Robot Programming with Lisp

Introduction to Functional Programming

A little bit of Lisp

Functional Programming. Pure Functional Programming

Introduction to Functional Programming and basic Lisp

Functional Programming. Big Picture. Design of Programming Languages

INF4820. Common Lisp: Closures and Macros

Modern Programming Languages. Lecture LISP Programming Language An Introduction

Scheme. Functional Programming. Lambda Calculus. CSC 4101: Programming Languages 1. Textbook, Sections , 13.7

Introduction to Scheme

Heap storage. Dynamic allocation and stacks are generally incompatible.

COMMOM OBJECT ORIENTED LISP SYSTEMS

Common LISP-Introduction

Scheme in Scheme: The Metacircular Evaluator Eval and Apply

A Brief Introduction to Common Lisp

Functional Languages. CSE 307 Principles of Programming Languages Stony Brook University

Functional Programming

CSCC24 Functional Programming Scheme Part 2

Project 2: Scheme Interpreter

Introduction to LISP. York University Department of Computer Science and Engineering. York University- CSE V.

Summer 2017 Discussion 10: July 25, Introduction. 2 Primitives and Define

Streams, Delayed Evaluation and a Normal Order Interpreter. CS 550 Programming Languages Jeremy Johnson

Allegro CL Certification Program

Common Lisp. Blake McBride

SCHEME 10 COMPUTER SCIENCE 61A. July 26, Warm Up: Conditional Expressions. 1. What does Scheme print? scm> (if (or #t (/ 1 0)) 1 (/ 1 0))

Class Structure. Prerequisites

CSc 520 Principles of Programming Languages

Recursive Functions of Symbolic Expressions and Their Computation by Machine Part I

Racket. CSE341: Programming Languages Lecture 14 Introduction to Racket. Getting started. Racket vs. Scheme. Example.

FP Foundations, Scheme

CS61A Discussion Notes: Week 11: The Metacircular Evaluator By Greg Krimer, with slight modifications by Phoebus Chen (using notes from Todd Segal)

Lecture #2 Kenneth W. Flynn RPI CS

Lisp Basic Example Test Questions

Functional Programming Lecture 1: Introduction

Scheme: Expressions & Procedures

Introduction to lambda calculus Part 3

Functional programming with Common Lisp

NCCU 資訊碩專班 Advanced Programming Languages 高等程式語言 資科系陳恭副教授. Instructor: Spring Lecture 6: Functional Programming, Lisp, Scheme-1 修訂版

Functional Programming Languages (FPL)

An Explicit Continuation Evaluator for Scheme

Principles of Programming Languages 2017W, Functional Programming

Below are example solutions for each of the questions. These are not the only possible answers, but they are the most common ones.

Symbolic Programming. Dr. Zoran Duric () Symbolic Programming 1/ 89 August 28, / 89

Common LISP Tutorial 1 (Basic)

Common Lisp Object System Specification. 1. Programmer Interface Concepts

15 Unification and Embedded Languages in Lisp

Introduction to Lisp

Documentation for LISP in BASIC

FUNKCIONÁLNÍ A LOGICKÉ PROGRAMOVÁNÍ 4. LISP: PROMĚNNÉ, DALŠÍ VLASTNOSTI FUNKCÍ, BLOKY, MAPOVACÍ FUNKCIONÁLY, ITERAČNÍ CYKLY,

Topic III. LISP : functions, recursion, and lists References: Chapter 3 of Concepts in programming languages by J. C. Mitchell. CUP, 2003.

A Genetic Algorithm Implementation

Notes on Higher Order Programming in Scheme. by Alexander Stepanov

Concepts of programming languages

Sample Final Exam Questions

TAIL RECURSION, SCOPE, AND PROJECT 4 11

Fall Semester, The Metacircular Evaluator. Today we shift perspective from that of a user of computer langugaes to that of a designer of

6.184 Lecture 4. Interpretation. Tweaked by Ben Vandiver Compiled by Mike Phillips Original material by Eric Grimson

Announcement. Overview. LISP: A Quick Overview. Outline of Writing and Running Lisp.

An Introduction to Scheme

LECTURE 16. Functional Programming

Functional Programming

Fall 2018 Discussion 8: October 24, 2018 Solutions. 1 Introduction. 2 Primitives

CS A331 Programming Language Concepts

Recursive Functions of Symbolic Expressions and Their Application, Part I

Functional Languages. Hwansoo Han

Scheme Tutorial. Introduction. The Structure of Scheme Programs. Syntax

Homework 1. Reading. Problems. Handout 3 CSCI 334: Spring, 2012

John McCarthy IBM 704

6.037 Lecture 4. Interpretation. What is an interpreter? Why do we need an interpreter? Stages of an interpreter. Role of each part of the interpreter

Project 5 - The Meta-Circular Evaluator

CS251 Programming Languages Handout # 47 Prof. Lyn Turbak May 22, 2005 Wellesley College. Scheme

Deferred operations. Continuations Structure and Interpretation of Computer Programs. Tail recursion in action.

11/6/17. Functional programming. FP Foundations, Scheme (2) LISP Data Types. LISP Data Types. LISP Data Types. Scheme. LISP: John McCarthy 1958 MIT

CS 314 Principles of Programming Languages

Chapter 1. Fundamentals of Higher Order Programming

INF4820: Algorithms for Artificial Intelligence and Natural Language Processing. More Common Lisp

CS 480. Lisp J. Kosecka George Mason University. Lisp Slides

4.2 Variations on a Scheme -- Lazy Evaluation

Fall 2017 Discussion 7: October 25, 2017 Solutions. 1 Introduction. 2 Primitives

CS 61A Interpreters, Tail Calls, Macros, Streams, Iterators. Spring 2019 Guerrilla Section 5: April 20, Interpreters.

4/19/2018. Chapter 11 :: Functional Languages

Lisp. Versions of LISP

(Func&onal (Programming (in (Scheme)))) Jianguo Lu

Spring 2018 Discussion 7: March 21, Introduction. 2 Primitives

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen

1.3. Conditional expressions To express case distinctions like

Symbolic Computation and Common Lisp

Functional programming techniques

Imperative, OO and Functional Languages A C program is

Lambda Calculus. Gunnar Gotshalks LC-1

Chapter 11 :: Functional Languages

Programming Language Pragmatics

Allegro CL Certification Program

Transcription:

Section 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

John McCarthy http://www.independent.co.uk/news/obituaries/ john-mccarthy-computer-scientist-known-as-thefather-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 Evolution of Software Languages 2

John McCarthy http://www.independent.co.uk/news/obituaries/ john-mccarthy-computer-scientist-known-as-thefather-of-ai-6255307.html Lispers say these are LISP... Arc, AutoLISP, Father Clojure, of LISP Common Lisp, Emacs Credited Lisp, EuLisp, with term Franz "AI" Lisp, Hy, Interlisp, Built on ISLISP, the IBM LeLisp, 604/9 LFE, Maclisp, Originated MDL, Newlisp, at MIT NIL, and at Picolisp, Portable Stanford 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

LISP I Programmer's Manual (March 1960) Define a function collapse: given some implementation for a function append: Evolution of Software Languages 4

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

(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

(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 7 https://en.wikipedia.org/wiki/symbolics

(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 http://www.computerhistory.org/ revolution/artificialintelligence-robotics/13/290/1254 Evolution of Software Languages 8 https://en.wikipedia.org/wiki/symbolics

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)))))) Evolution of Software Languages 9 http://landoflisp.com/source.html

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

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

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

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

Carl Hewitt 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 14

The Actor Model1 Evolution of Software Languages 15

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

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

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

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) (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 (newline)))) '$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 (define c1 (NEW counter 0)) (define c2 (NEW counter 5)) '$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$)) (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 19

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)))) (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$))) (define Welcome (list c1 (NEW to '$new$ counter DrScheme, '$scheduler$ (list 0)) version 'lambda (list 372 'ignore) [3m]. (list '$switch$ '$scheduler$) (list 'c2 (list 'quote 'up) 5) (list '$exit$ '$scheduler$))) (list '$new$ '$scheduler$ (list (define Language: 'lambda c2 (list (NEW 'ignore) Standard counter (list '$switch$ 5)) (R5RS) '$scheduler$) custom. (list 'c1 (list 'quote 'display)) (list '$exit$ '$scheduler$))) (list '$new$ '$scheduler$ (list 'lambda (list 'ignore) (list '$switch$ '$scheduler$) started (list 'c2 (list 'quote 'display)) (list '$exit$ '$scheduler$))) (list '$exit$ '$scheduler$))) (list '$start$ '$scheduler$)) (SEND c2 down 2) (SEND value=1 c1 up 1) (SEND value=8 c2 up 5) (SEND no c1 more display) processes (SEND c2 display)))) (define act-p (eval p (interaction-environment))) (act-p)) Evolution of Software Languages 20

The Actor Model3 <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> <acquaintance> <message> <argument> ::= (METHOD (<message> <argument>*) <expression>*) ::= identifier ::= identifier ::= identifier Evolution of Software Languages 21

The Actor Model4 (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))))))) Evolution of Software Languages 22

The Actor Model4 (define FactCust (BEHAVIOR (customer number1) (METHOD (result number2) (SEND customer result (* number1 number2))))) (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))))))) Evolution of Software Languages 23

The Actor Model4 (define FactCust (BEHAVIOR (customer number1) (METHOD (result number2) (SEND customer result (* number1 number2))))) (define Factorial (BEHAVIOR () (METHOD (doit customer number) (BECOME Factorial) (define User (display number) (newline) (BEHAVIOR (fact) (if (= number 0) (METHOD (doit number) (SEND customer result 1) (SEND fact doit SELF number)) (let ((x (NEW FactCust customer number))) (METHOD (result number) (SEND SELF doit x (- number 1))))))) (display (list "Value= " number)) (newline)))) Evolution of Software Languages 24

The Actor Model4 (define FactCust (BEHAVIOR (customer number1) (METHOD (result number2) (SEND customer result (* number1 number2))))) (define Factorial (BEHAVIOR () (METHOD (doit customer number) (BECOME Factorial) (define User (display number) (newline) (BEHAVIOR (fact) (if (= number 0) (METHOD (doit number) (SEND customer result 1) (SEND fact doit SELF number)) (let ((x (NEW FactCust customer number))) (METHOD (result number) (SEND SELF doit x (- number 1))))))) (display (list "Value= " number)) (newline)))) (define fact (NEW Factorial)) (SEND (NEW User fact) doit 10) (SEND (NEW User fact) doit 4) Evolution of Software Languages 25

The Actor Model5 (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)))) Evolution of Software Languages 26 (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)

The Actor Model6 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 Evolution of Software Languages 27

Guy Steele - Gerald Sussman https://en.wikipedia.org/wiki/guy_l._steele,_jr. Researchers at MIT Built "Scheme" Common Lisp SICP PhD with Seymour Papert PhD with http://cunydhi.commons.gc.cuny.edu/2015/03/21/ should-we-fear-intelligent-machines/ Evolution of Software Languages 28

The case of Scheme from AIM-848 Evolution of Software Languages 29

Scheme and Actors This work developed out of an initial attempt to understand the. actorness of actors. Steele thought he understood it, but couldn't explain it; Sussman suggested the experimental approach of actually building an "ACTORS interpreter". This interpreter attempted to intermix the use of actors and LISP lambda expressions in a clean manner. When it was completed, we discovered that the "actors" and the lambda expressions were identical in implementation. Once we had discovered this, all the rest fell into place, and it was only natural to begin thinking about actors in terms of lambda calculus. The original interpreter was call-by-name for various reasons from AIM-349 Evolution of Software Languages 30

A timeline for Scheme1 43pp 35pp 76pp Evolution of Software Languages 31

A timeline for Scheme2 43pp 50pp 88pp 1986 1998 1991 2007 55pp 90pp DRAFT Evolution of Software Languages 32 + IEEE Standard 1178-1990

Semantics for Scheme1 AIM-349 informal lambda-calculus substitution semantics AIM-452 informal AIM-848 (RRRS)... a formal definition of the semantics of Scheme will be included in a separate report... R3RS denotational semantics + rewrite rules R4RS denotational semantics + rewrite rules + macros (added support for immutables) R5RS denotational semantics + syntactic forms R6RS operational semantics R7RS Evolution of Software Languages 33 denotational semantics + syntactic forms (added support for dynamic-wind)

Semantics for Scheme2 Page 33 from R3RS Evolution of Software Languages 34

e.g. argument evaluation (4) The argument forms (and procedure f'orm) may in principle be evaluated i n any order. This is unlike the usual LISP left-to-right order. (All SCHEI'lE interpreters implemented so far have in fact performed left-to-right evaluation, 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 them right-to-left, e.g. to get things on a stack in the correct order.} AIM-452 A list whose first element is not the keyword of a special form indicates a procedure eall. The operator and operand expressions arevaluated and the resulting procedure is passed the resulting arguments. In contrast to other dialects of Lisp the order of evaluation is not specified, and the operator expression and the operand expressions are always evaluated with the same evaluation rules. AIM-848 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. ℇ (E 0 E*) = λρκ. ℇ*(permute ( E 0 E*)) ρ (λε*. ((λε*. applicate (ε* 1) (ε* 1) κ) (unpermute ε*))) Evolution of Software Languages 35

Glitches1 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) > Evolution of Software Languages 36

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

Evolution of Software Languages Glitches2 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>

Evolution of Software Languages Glitches2 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

Showcase: metacircularity1 (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)))) Evolution of Software Languages (loop "Lisp in 100 lines"))

Showcase: metacircularity2 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)... this is where I feed the interpreter 3x to itself Lisp in 100 lines level:4>(+ 1 2) 3 Evolution of Software Languages

Showcase: metacircularity3 (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)... Evolution of Software Languages expression)))

Showcase: metacircularity3 (define (evaluate expression) (define (error message qualifier) (display message) (set! environment rollback) (if (symbol? expression) (loop qualifier)) (evaluate-variable expression) (if (pair? ; expression) functions (apply (if (equal? (define (car (bind-variable expression) 'begin) variable evaluate-begin value)... (if (equal? (define (car (bind-parameters expression) 'define) parameters evaluate-define arguments)... (if (define (equal? (evaluate-sequence (car expression) 'if) expressions) evaluate-if... (if (define (equal? (make-procedure (car expression) parameters 'lambda) expressions) evaluate-lambda... (if (equal? (car expression) 'quote) evaluate-quote ; evaluation (if (equal? functions (car expression) 'set!) evaluate-set! (evaluate-application (car expression)))))))) (cdr expression))... expression))) (if (symbol? expression) (evaluate-variable expression) (if (pair? expression)... Evolution of Software Languages expression)))

Showcase: metacircularity3 (define (evaluate expression) (define (error message qualifier) (display message) (set! environment rollback) (loop qualifier)) (define (make-procedure parameters expressions) (define lexical-environment environment) ; functions (define procedure '()) (lambda arguments (define (bind-variable variable value)... (define dynamic-environment environment) (define (bind-parameters parameters arguments)... (set! environment lexical-environment) (define (evaluate-sequence expressions)... (bind-parameters parameters arguments) (define (make-procedure parameters expressions)... (begin (set! procedure (evaluate-sequence expressions)) ; evaluation functions (set! environment dynamic-environment) procedure)))... (if (symbol? expression) (evaluate-variable expression) (if (pair? expression)... Evolution of Software Languages expression)))

Conclusion 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... Evolution of Software Languages 45

Assignment 1. Construct an unbounded queue in the actor model 2. Make Lisp-in-100-lines run in Racket 3. Translate it into (a) Lisp Evolution of Software Languages 46