Section 10: LISP to Scheme. Evolution of Software Languages

Size: px
Start display at page:

Download "Section 10: LISP to Scheme. Evolution of Software Languages"

Transcription

1 Section Evolution of Software Languages Theo D'Hondt Bachelor of Computer Science Faculty of Sciences and Bio-Engineering Sciences Vrije Universiteit Brussel Academic Year Evolution of Software Languages 1

2 John McCarthy john-mccarthy-computer-scientist-known-as-thefather-of-ai 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

3 John McCarthy john-mccarthy-computer-scientist-known-as-thefather-of-ai 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

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

5 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

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 6

7 (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

8 (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 revolution/artificialintelligence-robotics/13/290/1254 Evolution of Software Languages 8

9 LISP example1 (defparameter *width* 100) (defparameter *height* 30) (defparameter *jungle* '( )) (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

10 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

11 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

12 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

13 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

14 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

15 The Actor Model1 Evolution of Software Languages 15

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 16

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 17

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) (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

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) (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

20 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

21 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

22 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

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) (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

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

25 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

26 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)

27 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

28 Guy Steele - Gerald Sussman Researchers at MIT Built "Scheme" Common Lisp SICP PhD with Seymour Papert PhD with should-we-fear-intelligent-machines/ Evolution of Software Languages 28

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

30 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

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

32 A timeline for Scheme2 43pp 50pp 88pp pp 90pp DRAFT Evolution of Software Languages 32 + IEEE Standard

33 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)

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

35 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

36 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

37 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

38 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>

39 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

40 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"))

41 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

42 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)))

43 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)))

44 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)))

45 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

46 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

Functional Programming with Common Lisp

Functional Programming with Common Lisp Functional Programming with Common Lisp Kamen Tomov ktomov@hotmail.com July 03, 2015 Table of Contents What is This About? Functional Programming Specifics Is Lisp a Functional Language? Lisp Says Hi Functional

More information

CS 314 Principles of Programming Languages

CS 314 Principles of Programming Languages CS 314 Principles of Programming Languages Lecture 16: Functional Programming Zheng (Eddy Zhang Rutgers University April 2, 2018 Review: Computation Paradigms Functional: Composition of operations on data.

More information

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

INF4820: Algorithms for Artificial Intelligence and Natural Language Processing. Common Lisp Fundamentals INF4820: Algorithms for Artificial Intelligence and Natural Language Processing Common Lisp Fundamentals Stephan Oepen & Murhaf Fares Language Technology Group (LTG) August 30, 2017 Last Week: What is

More information

Functional Programming. Pure Functional Languages

Functional Programming. Pure Functional Languages Functional Programming Pure functional PLs S-expressions cons, car, cdr Defining functions read-eval-print loop of Lisp interpreter Examples of recursive functions Shallow, deep Equality testing 1 Pure

More information

Functional Programming. Pure Functional Languages

Functional Programming. Pure Functional Languages Functional Programming Pure functional PLs S-expressions cons, car, cdr Defining functions read-eval-print loop of Lisp interpreter Examples of recursive functions Shallow, deep Equality testing 1 Pure

More information

Organization of Programming Languages CS3200/5200N. Lecture 11

Organization of Programming Languages CS3200/5200N. Lecture 11 Organization of Programming Languages CS3200/5200N Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio.edu Functional vs. Imperative The design of the imperative languages

More information

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

FUNKCIONÁLNÍ A LOGICKÉ PROGRAMOVÁNÍ 2. ÚVOD DO LISPU: ATOMY, SEZNAMY, FUNKCE, FUNKCIONÁLNÍ A LOGICKÉ PROGRAMOVÁNÍ 2. ÚVOD DO LISPU: ATOMY, SEZNAMY, FUNKCE, 2011 Jan Janoušek MI-FLP Evropský sociální fond Praha & EU: Investujeme do vaší budoucnosti L I S P - Introduction L I S P

More information

Robot Programming with Lisp

Robot Programming with Lisp 2. Imperative Programming Institute for Artificial University of Bremen Lisp the Language LISP LISt Processing language 2 Lisp the Language LISP LISt Processing language (LISP Lots of Irritating Superfluous

More information

Introduction to Functional Programming

Introduction to Functional Programming Introduction to Functional Programming Xiao Jia xjia@cs.sjtu.edu.cn Summer 2013 Scheme Appeared in 1975 Designed by Guy L. Steele Gerald Jay Sussman Influenced by Lisp, ALGOL Influenced Common Lisp, Haskell,

More information

A little bit of Lisp

A little bit of Lisp B.Y. Choueiry 1 Instructor s notes #3 A little bit of Lisp Introduction to Artificial Intelligence CSCE 476-876, Fall 2017 www.cse.unl.edu/~choueiry/f17-476-876 Read LWH: Chapters 1, 2, 3, and 4. Every

More information

Functional Programming. Pure Functional Programming

Functional Programming. Pure Functional Programming Functional Programming Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends only on the values of its sub-expressions (if any).

More information

Introduction to Functional Programming and basic Lisp

Introduction to Functional Programming and basic Lisp Introduction to Functional Programming and basic Lisp Based on Slides by Yves Lespérance & Peter Roosen-Runge 1 Functional vs Declarative Programming declarative programming uses logical statements to

More information

Functional Programming. Big Picture. Design of Programming Languages

Functional Programming. Big Picture. Design of Programming Languages Functional Programming Big Picture What we ve learned so far: Imperative Programming Languages Variables, binding, scoping, reference environment, etc What s next: Functional Programming Languages Semantics

More information

INF4820. Common Lisp: Closures and Macros

INF4820. Common Lisp: Closures and Macros INF4820 Common Lisp: Closures and Macros Erik Velldal University of Oslo Oct. 19, 2010 Erik Velldal INF4820 1 / 22 Topics for Today More Common Lisp A quick reminder: Scope, binding and shadowing Closures

More information

Modern Programming Languages. Lecture LISP Programming Language An Introduction

Modern Programming Languages. Lecture LISP Programming Language An Introduction Modern Programming Languages Lecture 18-21 LISP Programming Language An Introduction 72 Functional Programming Paradigm and LISP Functional programming is a style of programming that emphasizes the evaluation

More information

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

Scheme. Functional Programming. Lambda Calculus. CSC 4101: Programming Languages 1. Textbook, Sections , 13.7 Scheme Textbook, Sections 13.1 13.3, 13.7 1 Functional Programming Based on mathematical functions Take argument, return value Only function call, no assignment Functions are first-class values E.g., functions

More information

Introduction to Scheme

Introduction to Scheme How do you describe them Introduction to Scheme Gul Agha CS 421 Fall 2006 A language is described by specifying its syntax and semantics Syntax: The rules for writing programs. We will use Context Free

More information

Heap storage. Dynamic allocation and stacks are generally incompatible.

Heap storage. Dynamic allocation and stacks are generally incompatible. Heap storage Dynamic allocation and stacks are generally incompatible. 1 Stack and heap location Pointer X points to stack storage in procedure Q's activation record that no longer is live (exists) when

More information

COMMOM OBJECT ORIENTED LISP SYSTEMS

COMMOM OBJECT ORIENTED LISP SYSTEMS COMMOM OBJECT ORIENTED LISP SYSTEMS HISTORY: The following information is derived from the history section of dpans Common Lisp. Lisp is a family of languages with a long history. Early key ideas in Lisp

More information

Common LISP-Introduction

Common LISP-Introduction Common LISP-Introduction 1. The primary data structure in LISP is called the s-expression (symbolic expression). There are two basic types of s-expressions: atoms and lists. 2. The LISP language is normally

More information

Scheme in Scheme: The Metacircular Evaluator Eval and Apply

Scheme in Scheme: The Metacircular Evaluator Eval and Apply Scheme in Scheme: The Metacircular Evaluator Eval and Apply CS21b: Structure and Interpretation of Computer Programs Brandeis University Spring Term, 2015 The metacircular evaluator is A rendition of Scheme,

More information

A Brief Introduction to Common Lisp

A Brief Introduction to Common Lisp A Brief Introduction to Common Lisp David Gu Schloer Consulting Group david_guru@gty.org.in A Brief History Originally specified in 1958, Lisp is the second-oldest highlevel programming language in widespread

More information

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

Functional Languages. CSE 307 Principles of Programming Languages Stony Brook University Functional Languages CSE 307 Principles of Programming Languages Stony Brook University http://www.cs.stonybrook.edu/~cse307 1 Historical Origins 2 The imperative and functional models grew out of work

More information

Functional Programming

Functional Programming Functional Programming CS331 Chapter 14 Functional Programming Original functional language is LISP LISt Processing The list is the fundamental data structure Developed by John McCarthy in the 60 s Used

More information

CSCC24 Functional Programming Scheme Part 2

CSCC24 Functional Programming Scheme Part 2 CSCC24 Functional Programming Scheme Part 2 Carolyn MacLeod 1 winter 2012 1 Based on slides from Anya Tafliovich, and with many thanks to Gerald Penn and Prabhakar Ragde. 1 The Spirit of Lisp-like Languages

More information

Project 2: Scheme Interpreter

Project 2: Scheme Interpreter Project 2: Scheme Interpreter CSC 4101, Fall 2017 Due: 12 November 2017 For this project, you will implement a simple Scheme interpreter in C++ or Java. Your interpreter should be able to handle the same

More information

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

Introduction to LISP. York University Department of Computer Science and Engineering. York University- CSE V. Introduction to LISP York University Department of Computer Science and Engineering York University- CSE 3401- V. Movahedi 11_LISP 1 Introduction to LISP Evaluation and arguments S- expressions Lists Numbers

More information

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

Summer 2017 Discussion 10: July 25, Introduction. 2 Primitives and Define CS 6A Scheme Summer 207 Discussion 0: July 25, 207 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,

More information

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

Streams, Delayed Evaluation and a Normal Order Interpreter. CS 550 Programming Languages Jeremy Johnson Streams, Delayed Evaluation and a Normal Order Interpreter CS 550 Programming Languages Jeremy Johnson 1 Theme This lecture discusses the stream model of computation and an efficient method of implementation

More information

Allegro CL Certification Program

Allegro CL Certification Program Allegro CL Certification Program Lisp Programming Series Level I Presented by 1 About David Margolies Manager, Documentation, Franz Inc Been working with Lisp since 1984 dm@franz.com 2 About Franz Inc.

More information

Common Lisp. Blake McBride

Common Lisp. Blake McBride Contents Common Lisp Blake McBride (blake@mcbride.name) 1 Data Types 2 2 Numeric Hierarchy 3 3 Comments 3 4 List Operations 4 5 Evaluation and Quotes 5 6 String Operations 5 7 Predicates 6 8 Math Predicates

More information

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))

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)) SCHEME 0 COMPUTER SCIENCE 6A July 26, 206 0. Warm Up: Conditional Expressions. What does Scheme print? scm> (if (or #t (/ 0 (/ 0 scm> (if (> 4 3 (+ 2 3 4 (+ 3 4 (* 3 2 scm> ((if (< 4 3 + - 4 00 scm> (if

More information

Class Structure. Prerequisites

Class Structure. Prerequisites Class Structure Procedural abstraction and recursion 6.037 - Structure and Interpretation of Computer Programs Mike Phillips, Benjamin Barenblat, Leon Shen, Ben Vandiver, Alex Vandiver, Arthur Migdal Massachusetts

More information

CSc 520 Principles of Programming Languages

CSc 520 Principles of Programming Languages CSc 520 Principles of Programming Languages 3: Scheme Introduction Christian Collberg collberg@cs.arizona.edu Department of Computer Science University of Arizona Copyright c 2005 Christian Collberg [1]

More information

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

Recursive Functions of Symbolic Expressions and Their Computation by Machine Part I Recursive Functions of Symbolic Expressions and Their Computation by Machine Part I by John McCarthy Ik-Soon Kim Winter School 2005 Feb 18, 2005 Overview Interesting paper with By John Mitchell Interesting

More information

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

Racket. CSE341: Programming Languages Lecture 14 Introduction to Racket. Getting started. Racket vs. Scheme. Example. Racket Next 2+ weeks will use the Racket language (not ML) and the DrRacket programming environment (not emacs) Installation / basic usage instructions on course website CSE34: Programming Languages Lecture

More information

FP Foundations, Scheme

FP Foundations, Scheme FP Foundations, Scheme In Text: Chapter 15 1 Functional Programming -- Prelude We have been discussing imperative languages C/C++, Java, Fortran, Pascal etc. are imperative languages Imperative languages

More information

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

CS61A Discussion Notes: Week 11: The Metacircular Evaluator By Greg Krimer, with slight modifications by Phoebus Chen (using notes from Todd Segal) CS61A Discussion Notes: Week 11: The Metacircular Evaluator By Greg Krimer, with slight modifications by Phoebus Chen (using notes from Todd Segal) What is the Metacircular Evaluator? It is the best part

More information

Lecture #2 Kenneth W. Flynn RPI CS

Lecture #2 Kenneth W. Flynn RPI CS Outline Programming in Lisp Lecture #2 Kenneth W. Flynn RPI CS Items from last time Recursion, briefly How to run Lisp I/O, Variables and other miscellany Lists Arrays Other data structures Jin Li lij3@rpi.edu

More information

Lisp Basic Example Test Questions

Lisp Basic Example Test Questions 2009 November 30 Lisp Basic Example Test Questions 1. Assume the following forms have been typed into the interpreter and evaluated in the given sequence. ( defun a ( y ) ( reverse y ) ) ( setq a (1 2

More information

Functional Programming Lecture 1: Introduction

Functional Programming Lecture 1: Introduction Functional Programming Lecture 1: Introduction Viliam Lisý Artificial Intelligence Center Department of Computer Science FEE, Czech Technical University in Prague viliam.lisy@fel.cvut.cz Acknowledgements

More information

Scheme: Expressions & Procedures

Scheme: Expressions & Procedures Scheme: Expressions & Procedures CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Friday, March 31, 2017 Glenn G. Chappell Department of Computer Science University

More information

Introduction to lambda calculus Part 3

Introduction to lambda calculus Part 3 Introduction to lambda calculus Part 3 Antti-Juhani Kaijanaho 2017-01-27... 1 Untyped lambda calculus... 2 Typed lambda calculi In an untyped lambda calculus extended with integers, it is required that

More information

Functional programming with Common Lisp

Functional programming with Common Lisp Functional programming with Common Lisp Dr. C. Constantinides Department of Computer Science and Software Engineering Concordia University Montreal, Canada August 11, 2016 1 / 81 Expressions and functions

More information

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

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

More information

Functional Programming Languages (FPL)

Functional Programming Languages (FPL) Functional Programming Languages (FPL) 1. Definitions... 2 2. Applications... 2 3. Examples... 3 4. FPL Characteristics:... 3 5. Lambda calculus (LC)... 4 6. Functions in FPLs... 7 7. Modern functional

More information

An Explicit Continuation Evaluator for Scheme

An Explicit Continuation Evaluator for Scheme Massachusetts Institute of Technology Course Notes 2 6.844, Spring 05: Computability Theory of and with Scheme February 17 Prof. Albert R. Meyer revised March 3, 2005, 1265 minutes An Explicit Continuation

More information

Principles of Programming Languages 2017W, Functional Programming

Principles of Programming Languages 2017W, Functional Programming Principles of Programming Languages 2017W, Functional Programming Assignment 3: Lisp Machine (16 points) Lisp is a language based on the lambda calculus with strict execution semantics and dynamic typing.

More information

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

Below are example solutions for each of the questions. These are not the only possible answers, but they are the most common ones. 6.001, Fall Semester, 2002 Quiz II Sample solutions 1 MASSACHVSETTS INSTITVTE OF TECHNOLOGY Department of Electrical Engineering and Computer Science 6.001 Structure and Interpretation of Computer Programs

More information

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

Symbolic Programming. Dr. Zoran Duric () Symbolic Programming 1/ 89 August 28, / 89 Symbolic Programming Symbols: +, -, 1, 2 etc. Symbolic expressions: (+ 1 2), (+ (* 3 4) 2) Symbolic programs are programs that manipulate symbolic expressions. Symbolic manipulation: you do it all the

More information

Common LISP Tutorial 1 (Basic)

Common LISP Tutorial 1 (Basic) Common LISP Tutorial 1 (Basic) CLISP Download https://sourceforge.net/projects/clisp/ IPPL Course Materials (UST sir only) Download https://silp.iiita.ac.in/wordpress/?page_id=494 Introduction Lisp (1958)

More information

Common Lisp Object System Specification. 1. Programmer Interface Concepts

Common Lisp Object System Specification. 1. Programmer Interface Concepts Common Lisp Object System Specification 1. Programmer Interface Concepts Authors: Daniel G. Bobrow, Linda G. DeMichiel, Richard P. Gabriel, Sonya E. Keene, Gregor Kiczales, and David A. Moon. Draft Dated:

More information

15 Unification and Embedded Languages in Lisp

15 Unification and Embedded Languages in Lisp 15 Unification and Embedded Languages in Lisp Chapter Objectives Chapter Contents Pattern matching in Lisp: Database examples Full unification as required for Predicate Calculus problem solving Needed

More information

Introduction to Lisp

Introduction to Lisp Last update: February 16, 2010 Introduction to Lisp Dana Nau Dana Nau 1 Outline I assume you know enough about computer languages that you can learn new ones quickly, so I ll go pretty fast If I go too

More information

Documentation for LISP in BASIC

Documentation for LISP in BASIC Documentation for LISP in BASIC The software and the documentation are both Copyright 2008 Arthur Nunes-Harwitt LISP in BASIC is a LISP interpreter for a Scheme-like dialect of LISP, which happens to have

More information

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

FUNKCIONÁLNÍ A LOGICKÉ PROGRAMOVÁNÍ 4. LISP: PROMĚNNÉ, DALŠÍ VLASTNOSTI FUNKCÍ, BLOKY, MAPOVACÍ FUNKCIONÁLY, ITERAČNÍ CYKLY, FUNKCIONÁLNÍ A LOGICKÉ PROGRAMOVÁNÍ 4. LISP: PROMĚNNÉ, DALŠÍ VLASTNOSTI FUNKCÍ, BLOKY, MAPOVACÍ FUNKCIONÁLY, ITERAČNÍ CYKLY, 2011 Jan Janoušek MI-FLP Evropský sociální fond Praha & EU: Investujeme do vaší

More information

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

Topic III. LISP : functions, recursion, and lists References: Chapter 3 of Concepts in programming languages by J. C. Mitchell. CUP, 2003. Topic III LISP : functions, recursion, and lists References: Chapter 3 of Concepts in programming languages by J. C. Mitchell. CUP, 2003. Chapters 5( 4.5) and 13( 1) of Programming languages: Design and

More information

A Genetic Algorithm Implementation

A Genetic Algorithm Implementation A Genetic Algorithm Implementation Roy M. Turner (rturner@maine.edu) Spring 2017 Contents 1 Introduction 3 2 Header information 3 3 Class definitions 3 3.1 Individual..........................................

More information

Notes on Higher Order Programming in Scheme. by Alexander Stepanov

Notes on Higher Order Programming in Scheme. by Alexander Stepanov by Alexander Stepanov August 1986 INTRODUCTION Why Scheme? Because it allows us to deal with: 1. Data Abstraction - it allows us to implement ADT (abstact data types) in a very special way. The issue of

More information

Concepts of programming languages

Concepts of programming languages Concepts of programming languages Lecture 7 Wouter Swierstra 1 Last time Relating evaluation and types How to handle variable binding in embedded languages? 2 DSLs: approaches A stand-alone DSL typically

More information

Sample Final Exam Questions

Sample Final Exam Questions 91.301, Organization of Programming Languages Fall 2015, Prof. Yanco Sample Final Exam Questions Note that the final is a 3 hour exam and will have more questions than this handout. The final exam will

More information

TAIL RECURSION, SCOPE, AND PROJECT 4 11

TAIL RECURSION, SCOPE, AND PROJECT 4 11 TAIL RECURSION, SCOPE, AND PROJECT 4 11 COMPUTER SCIENCE 61A Noveber 12, 2012 1 Tail Recursion Today we will look at Tail Recursion and Tail Call Optimizations in Scheme, and how they relate to iteration

More information

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

Fall Semester, The Metacircular Evaluator. Today we shift perspective from that of a user of computer langugaes to that of a designer of 1 MASSACHVSETTS INSTITVTE OF TECHNOLOGY Department of Electrical Engineering and Computer Science 6.001 Structure and Interpretation of Computer Programs Fall Semester, 1996 Lecture Notes { October 31,

More information

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

6.184 Lecture 4. Interpretation. Tweaked by Ben Vandiver Compiled by Mike Phillips Original material by Eric Grimson 6.184 Lecture 4 Interpretation Tweaked by Ben Vandiver Compiled by Mike Phillips Original material by Eric Grimson 1 Interpretation Parts of an interpreter Arithmetic calculator

More information

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

Announcement. Overview. LISP: A Quick Overview. Outline of Writing and Running Lisp. Overview Announcement Announcement Lisp Basics CMUCL to be available on sun.cs. You may use GNU Common List (GCL http://www.gnu.org/software/gcl/ which is available on most Linux platforms. There is also

More information

An Introduction to Scheme

An Introduction to Scheme An Introduction to Scheme Stéphane Ducasse stephane.ducasse@inria.fr http://stephane.ducasse.free.fr/ Stéphane Ducasse 1 Scheme Minimal Statically scoped Functional Imperative Stack manipulation Specification

More information

LECTURE 16. Functional Programming

LECTURE 16. Functional Programming LECTURE 16 Functional Programming WHAT IS FUNCTIONAL PROGRAMMING? Functional programming defines the outputs of a program as a mathematical function of the inputs. Functional programming is a declarative

More information

Functional Programming

Functional Programming Functional Programming CS 1025 Computer Science Fundamentals I Stephen M. Watt University of Western Ontario When the Function is the Thing In O-O programming, you typically know where an action is needed,

More information

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

Fall 2018 Discussion 8: October 24, 2018 Solutions. 1 Introduction. 2 Primitives CS 6A Scheme Fall 208 Discussion 8: October 24, 208 Solutions Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write

More information

CS A331 Programming Language Concepts

CS A331 Programming Language Concepts CS A331 Programming Language Concepts Lecture 10 Alternative Programming Languages (Functional LISP Declarative - PROLOG) March 24, 2014 Sam Siewert Functional PL Concepts Based on Lambda Calculus Output

More information

Recursive Functions of Symbolic Expressions and Their Application, Part I

Recursive Functions of Symbolic Expressions and Their Application, Part I Recursive Functions of Symbolic Expressions and Their Application, Part I JOHN MCCARTHY Review: Amit Kirschenbaum Seminar in Programming Languages Recursive Functions of Symbolic Expressions and Their

More information

Functional Languages. Hwansoo Han

Functional Languages. Hwansoo Han Functional Languages Hwansoo Han Historical Origins Imperative and functional models Alan Turing, Alonzo Church, Stephen Kleene, Emil Post, etc. ~1930s Different formalizations of the notion of an algorithm

More information

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

Scheme Tutorial. Introduction. The Structure of Scheme Programs. Syntax Scheme Tutorial Introduction Scheme is an imperative language with a functional core. The functional core is based on the lambda calculus. In this chapter only the functional core and some simple I/O is

More information

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

Homework 1. Reading. Problems. Handout 3 CSCI 334: Spring, 2012 Homework 1 Due 14 February Handout 3 CSCI 334: Spring, 2012 Reading 1. (Required) Mitchell, Chapter 3. 2. (As Needed) The Lisp Tutorial from the Links web page, as needed for the programming questions.

More information

John McCarthy IBM 704

John McCarthy IBM 704 How this course works SI 334: Principles of Programming Languages Lecture 2: Lisp Instructor: an arowy Lots of new languages Not enough class time to cover all features (e.g., Java over the course of 34-36:

More information

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

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 6.037 Lecture 4 Interpretation Interpretation Parts of an interpreter Meta-circular Evaluator (Scheme-in-scheme!) A slight variation: dynamic scoping Original material by Eric Grimson Tweaked by Zev Benjamin,

More information

Project 5 - The Meta-Circular Evaluator

Project 5 - The Meta-Circular Evaluator MASSACHVSETTS INSTITVTE OF TECHNOLOGY Department of Electrical Engineering and Computer Science 6.001 Structure and Interpretation of Computer Programs Fall Semester, 2005 Project 5 - The Meta-Circular

More information

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

CS251 Programming Languages Handout # 47 Prof. Lyn Turbak May 22, 2005 Wellesley College. Scheme CS251 Programming Languages Handout # 47 Prof. Lyn Turbak May 22, 2005 Wellesley College 1 Scheme Overview Scheme Scheme is a block-structured, lexically-scoped, properly tail-recursive dialect of Lisp

More information

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

Deferred operations. Continuations Structure and Interpretation of Computer Programs. Tail recursion in action. Deferred operations Continuations 6.037 - Structure and Interpretation of Computer Programs Mike Phillips (define the-cons (cons 1 #f)) (set-cdr! the-cons the-cons) (define (run-in-circles l) (+

More information

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

11/6/17. Functional programming. FP Foundations, Scheme (2) LISP Data Types. LISP Data Types. LISP Data Types. Scheme. LISP: John McCarthy 1958 MIT Functional programming FP Foundations, Scheme (2 In Text: Chapter 15 LISP: John McCarthy 1958 MIT List Processing => Symbolic Manipulation First functional programming language Every version after the

More information

CS 314 Principles of Programming Languages

CS 314 Principles of Programming Languages CS 314 Principles of Programming Languages Lecture 15: Review and Functional Programming Zheng (Eddy) Zhang Rutgers University March 19, 2018 Class Information Midterm exam forum open in Sakai. HW4 and

More information

Chapter 1. Fundamentals of Higher Order Programming

Chapter 1. Fundamentals of Higher Order Programming Chapter 1 Fundamentals of Higher Order Programming 1 The Elements of Programming Any powerful language features: so does Scheme primitive data procedures combinations abstraction We will see that Scheme

More information

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

INF4820: Algorithms for Artificial Intelligence and Natural Language Processing. More Common Lisp INF4820: Algorithms for Artificial Intelligence and Natural Language Processing More Common Lisp Stephan Oepen & Murhaf Fares Language Technology Group (LTG) September 6, 2017 Agenda 2 Previously Common

More information

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

CS 480. Lisp J. Kosecka George Mason University. Lisp Slides CS 480 Lisp J. Kosecka George Mason University Lisp Slides Symbolic Programming Symbols: +, -, 1, 2 etc. Symbolic expressions: (+ 1 2), (+ (* 3 4) 2) Symbolic programs are programs that manipulate symbolic

More information

4.2 Variations on a Scheme -- Lazy Evaluation

4.2 Variations on a Scheme -- Lazy Evaluation [Go to first, previous, next page; contents; index] 4.2 Variations on a Scheme -- Lazy Evaluation Now that we have an evaluator expressed as a Lisp program, we can experiment with alternative choices in

More information

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

Fall 2017 Discussion 7: October 25, 2017 Solutions. 1 Introduction. 2 Primitives CS 6A Scheme Fall 207 Discussion 7: October 25, 207 Solutions Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write

More information

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

CS 61A Interpreters, Tail Calls, Macros, Streams, Iterators. Spring 2019 Guerrilla Section 5: April 20, Interpreters. CS 61A Spring 2019 Guerrilla Section 5: April 20, 2019 1 Interpreters 1.1 Determine the number of calls to scheme eval and the number of calls to scheme apply for the following expressions. > (+ 1 2) 3

More information

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

4/19/2018. Chapter 11 :: Functional Languages Chapter 11 :: Functional Languages Programming Language Pragmatics Michael L. Scott Historical Origins The imperative and functional models grew out of work undertaken by Alan Turing, Alonzo Church, Stephen

More information

Lisp. Versions of LISP

Lisp. Versions of LISP Lisp Versions of LISP Lisp is an old language with many variants Lisp is alive and well today Most modern versions are based on Common Lisp LispWorks is based on Common Lisp Scheme is one of the major

More information

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

(Func&onal (Programming (in (Scheme)))) Jianguo Lu (Func&onal (Programming (in (Scheme)))) Jianguo Lu 1 Programming paradigms Func&onal No assignment statement No side effect Use recursion Logic OOP AOP 2 What is func&onal programming It is NOT what you

More information

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

Spring 2018 Discussion 7: March 21, Introduction. 2 Primitives CS 61A Scheme Spring 2018 Discussion 7: March 21, 2018 1 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme

More information

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen COP4020 Programming Languages Functional Programming Prof. Robert van Engelen Overview What is functional programming? Historical origins of functional programming Functional programming today Concepts

More information

1.3. Conditional expressions To express case distinctions like

1.3. Conditional expressions To express case distinctions like Introduction Much of the theory developed in the underlying course Logic II can be implemented in a proof assistant. In the present setting this is interesting, since we can then machine extract from a

More information

Symbolic Computation and Common Lisp

Symbolic Computation and Common Lisp Symbolic Computation and Common Lisp Dr. Neil T. Dantam CSCI-56, Colorado School of Mines Fall 28 Dantam (Mines CSCI-56) Lisp Fall 28 / 92 Why? Symbolic Computing: Much of this course deals with processing

More information

Functional programming techniques

Functional programming techniques Functional programming techniques o Currying o Continuations o Streams. Lazy evaluation Currying o Haskell B. Curry. o Second-order programming: o Functions that return other functions. o Example: A two-arguments

More information

Imperative, OO and Functional Languages A C program is

Imperative, OO and Functional Languages A C program is Imperative, OO and Functional Languages A C program is a web of assignment statements, interconnected by control constructs which describe the time sequence in which they are to be executed. In Java programming,

More information

Lambda Calculus. Gunnar Gotshalks LC-1

Lambda Calculus. Gunnar Gotshalks LC-1 Lambda Calculus LC-1 l- Calculus History Developed by Alonzo Church during 1930 s-40 s One fundamental goal was to describe what can be computed. Full definition of l-calculus is equivalent in power to

More information

Chapter 11 :: Functional Languages

Chapter 11 :: Functional Languages Chapter 11 :: Functional Languages Programming Language Pragmatics Michael L. Scott Copyright 2016 Elsevier 1 Chapter11_Functional_Languages_4e - Tue November 21, 2017 Historical Origins The imperative

More information

Programming Language Pragmatics

Programming Language Pragmatics Chapter 10 :: Functional Languages Programming Language Pragmatics Michael L. Scott Historical Origins The imperative and functional models grew out of work undertaken Alan Turing, Alonzo Church, Stephen

More information

Allegro CL Certification Program

Allegro CL Certification Program Allegro CL Certification Program Lisp Programming Series Level I Review David Margolies 1 Summary 1 A lisp session contains a large number of objects which is typically increased by user-created lisp objects

More information