Symbolic Programming. Symbolic Programming. Symbolic Programs for Playing Chess. AI in Practice: Playing Chess. Artificial Intelligence Chapter 2
|
|
- Stephanie O’Neal’
- 6 years ago
- Views:
Transcription
1 Symbolic Programming Symbolic Programming Artificial Intelligence Chapter 2 z Create symbols and symbolic expressions: ˆ NB Ž SNB Ž NBJŠ Š Bˆ KN BBBJ B Ž SB Ž K z Pass them around as arguments to procedures. z Manipulate them to infer new expressions: J B Ž SB Ž KNBJ B Ž B Ž UK BBB BJ ƒ B Ž SB Ž B Ž UK Symbolic Programs for Playing Chess AI in Practice: Playing Chess z Symbols: chess pieces z Expressions: legal moves eg.: Žƒ O Š SNB Žƒ O Š J BJˆ ƒ BšBKBJ Š BšBSKK
2 2.1 Rule-Based Reactive System Example Obstacle Detection Sensors for a Mobile Robot z Symbols: sensors, controls z Sensors names ˆ ƒ NB Š NBŽ ˆ NBŒ Š NBŒŽ ˆ NB ƒ B ƒ NBƒ ƒ NBˆƒ Ÿ z Control parameters: speed, direction speed B{œ NB Ž NBˆƒ } turn B {Ž ˆ NB ƒ Š NB Š } 2.2 Introduction to Lisp z Programs and data are represented as lists, i.e. ( expressions ) z An expression is a Lisp object or a list of zero or more expressions. z Examples: JKNBJSKNBJSBJKK z Symbols: SVNB O NB NB ˆ NBhqqNBh NB NB Ž z A Lisp program consists of a sequence of Lisp expressions. e.g.: J ˆ B ƒ BJšKBJLBšBšBKK 2.3 Interacting with Lisp z Lisp interpreter: read-eval-print loop z ƒž and ƒ Ž `BD D D D `BJMBUBVBWK S `BJ ƒ BK V
3 2.4 Functions in Lisp z ˆ : function definition J ˆ BŠ BJƒB K BBB BJ BJMBJ ƒ BƒK BBBBBBBBB BBBBBJ ƒ B KKKK J ˆ B ƒ BJšK BBB BJLBšBšKK `BJ ƒ BUK [ `BJŠ BUBVK W Eval and Apply z Eval takes the list and extracts the first element of the list and the list of arguments. z Eval passes the function associated with the symbol and the list of argument to apply. z Apply uses eval to evaluate the list of arguments. z Apply extracts the function definition and check the number of arguments. z Apply sends the evaluated arguments to eval to be evaluated. Conditional Statements z J ˆBtest conditional alternativek J ˆ B š O O BJ K BB BBJ ˆBJ B K BBBB BBBBBJMB BSK BBBBBB BJMB BKKK `BJ š O O BSK U Conditional Statements: z J BclausesK, clauses := Jtest bodyk* J ˆ B BJ K BBBJ BJJ`_B BV[KBJ BDeƒ I B B Šƒ Š Š PDKB ŽK BBBBBBBBBBBBBJJ BJ_B BKBJ_B BUKBJ_B BWKKB K BBBBBBBBBBBBBJJ BJ_BJ B BKBRK BBBBBBBBBBBBBBBBBBBBJ_BJ B BUKBRK BBBBBBBBBBBBBBBBBBBBJ_BJ B BWKBRKKB ŽK BBBBBBBBBBBBBJ B KKK
4 Using Defined Functions `BJ BUK `BJ BUYK v `BJ BYXK eƒ I B B Šƒ BŠ ŠP Recursive Functions z Reduce the original problem to simpler problems, and then apply itself to solve the simpler problems. z Break the problem down again, and again, until the pieces of the problem can be solved easily. z Problem reduction z Divide-and-conquer Recursive Functions: An Example z Lisp Example J ˆ B ƒ BJšB K BBBBJ ˆBJ_B BRK BBBBBBBBBS BBBBBBBBJLBšBJ ƒ BšBJOB BSKKKKK `BJ ƒ BUBUK Y z Evaluating Functions in Files BBBB`BJŽ ƒ BD ƒ PŽ D) 2.5 Environments, Symbols, and Scope z Assigning values to symbols `BJ B BK `B J B BUK U `B U `BJ B B K BBBBU `B U
5 Eval 1. If x is a number or string, return x. 2. If x is a symbol, then look up its value in the environment. 3. If x a special form, handle it accordingly 4. If x a list, send the function (first item) and arguments (the rest of items) to ƒ Ž. Apply 1. Look up the definition of the function 2. Use ƒž to evaluate each argument in the environment. 3. Create a new environment. 4. Use ƒž to evaluate the definition in the new environment. Structured Environments z An environment allocates storage for symbolic values. z Global environments as a large table. z A new environment points to the existing parent environment. z o determine the value of a symbol, ƒž first looks in the table pointed by the environment. If no entry exists, then ƒž looks in the parent environment. Scope `BJ BšBK ` J ˆ BŽ ƒžbjšk B BJ BšBJMBšBSKK B B JLBšBšKK nqecn `BJŽ ƒžbjmbšbskk SX `Bš `BJŽ BJJšBSK BBBBBJŽ BJJšBKK BBBBBBBBJŽ BJJšBUKK BBBBBBBBBBBJ BšKK BBBBBBBBJ BšKK BBBBBJ BšKK US S
6 n : Introducing Local Variables Environments Created during Function Invocation J ˆ B BJK BBBJ BDi Bƒ B Bˆ BRB B[\BDK BBBJŽ BJJ BJ ƒ KKBJ BJ ƒ BSRKKK BBBBBJ BJJ`B B KBJ BDv Š ŠCDKK BBBBBBBBBBBBBBBJJ^B B KBJ BDv BŽ CDKK BBBBBBBBBBBBBBBJ BJ BDn B CDKKKKK iwguu `BJ K i Bƒ B Bˆ BRB B[\BU v BŽ C 2.6 More on Functions z Functions with Local State `BJŽ BJšBJ BSKK BBB BBBBJ ˆ B ƒ Žƒ BJœK BBBBBBBBB BBJ BšB KBJ B BœKBJLBšBšKKK uswctgncuv `BJ ƒ Žƒ BK S `BJ ƒ Žƒ BUK V Lambda Functions z ˆ : define named functions. `BJ ˆ B ƒ BJšKBJLBšBšKK z Žƒ ƒ: creates unnamed functions. `BJŽƒ ƒbjškbjlbšbškk z ˆ : evaluates lambda functions or a symbol defined as a function. `BJˆ BJŽƒ ƒbarguments bodykk `BJˆ B#'Žƒ ƒbarguments bodykk `BJˆ B ƒ K
7 Functions as Arguments and ˆ ƒžž 2.7 List Processing `BJˆ ƒžžbeijžƒ ƒbjškbjlbšbškkbuk [ ` J ˆ B ƒ BJšB BˆK BBBBBBJ ˆBJ`BJˆ ƒžžbˆbškbjˆ ƒžžbˆb KKB B ŽKK fgetgcukpir ` J ƒ BSBBEIJŽƒ ƒbjškbjlbšbšbkkk `BJ B ƒžbeijžƒ ƒbjškbjqbsbškkk #^k Oh BJncodfcBJzKBJQBSBzKK SRVddYW` `BJ ƒ BSBB ƒžk v J BexpressionK `BJ B K u{o `BI u{o IJˆ B B Š K JhktuvBugeqpfBvjktfK `BJŽ BSBBUBVK `BJŽ BSBJŽ BBJŽ BUKKK JSBJBJUKKK Building and Accessing Elements in Lists Lists in Memory `BJ Bˆ BJŽ BSBBU VKK `BJŽ BJˆ Bˆ K J Bˆ KBJ ŠB ˆ KK JSBBUK `BJ Bˆ K JBUBVK `BJ Bˆ BSK S `BJ B BJŽ BBU VKK JBUBVK `BJ Bˆ B K `BJ BšBJ BSBKK JSBPBBK ` J B BJ BS J BBJKKKK JSBK `BJ ƒ BšK S `BJ B K JK `BJ ƒ BJ B KK `BJ ƒ B K
8 Lists in Memory: Illustrations Modifying Existing List Structures `BJ BšBJŽ BSBJŽ BKKK JSBJKK `BJ ˆBJˆ BJˆ BJ BšKKKBSK S `Bš JSBJSKK Comparing List Structures: Band ƒž Built-In List Manipulation Functions `BJ B BIˆ K hqq `BJ B BIˆ K v `BJ B BJŽ BIˆ KK JhqqK ` J B BJŽ BIˆ KK `BJ B B K JhqqK `BJ B B K v `BJ ƒžb BJŽ BIˆ KK v `BJ BšBIJS KB BIJUBVKK JUBVK `BJƒ BšB K `Bš JSBK `B( BšB K ;; destructive `Bš `BJ BšK JVBUBBSK `BJ BWBJƒ BIJS BUKBIJVBWKBIJXBYBZKKK JWBXBYBZK
9 Optional Arguments `BJ BIJKBIJJSKBJKBJUKKK ;; eq is used `BJ BIJKBIJJSKBJKBJUKK \ B#I ƒžk JJKBJUKK `BJ BIJSBKBIJJRBVKBJSBUKK BBBBBBBBBB\ BEIŽƒ ƒbjšb KBJ BJˆ BšK BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBJˆ B KKKK JJSBUKK List-Processing Examples: Homeworks z (p. 49) z ƒ ŠB(p. 50) z ƒ O ƒ (p. 50) z and ƒ (p. 51) z Žƒ (p. 40) z Data Abstraction: vtggo (p ) 2.8 Iterative Constructs: ƒ ƒ z ƒ ƒ NB ƒ NB ƒ ƒ NB `BJ ƒ ƒ BEIMBIJSBBUKBIJVBWBXKK JWBYB[K `BJ ƒ ƒ BEIJŽƒ ƒbjšb K BBBBBBBBBBBBBBBBBBBBBBBJ ˆBJ`BšB KBšB KK BBBBBBBBBBBBBBBBBBIJBYBWKBIJSB[BVKK JB[BWK `BJ BEIMBIJSBBUKK X z ( B index-var-specs (end-test result) body) z index-var-specs := (step-var init-val step-val) `BJ BJJ BSBJMB BSKKBBBBBB ; index-var-specs BBBBBBBBBJŒBSBJLBŒB KKK BBBBBBBBJJ_B BSRKBŒKBBBBBBB B; (end-test result) BBBBBBBBJ B KKBBBBBBBBBB B; body SUVWXYZ[ UXZZR
10 Ž NB z ( Ž (var expr result) body) ; var is bound to elements of list expr z ( (var expr result) body) ; var is an integer resulting from expr `BJ Ž BJšBIJƒB B KKBJ BšKK cde `BJ BJ BSRB KBJ B KK RSUVWXYZ[ SR 2.9 Monitoring and Debugging Programs z racing the programs `BJ ƒ B ƒ B ƒ K JtckugBuswctgK `BJ ƒ BJ ƒ BBKK SBg BtckugBB žbbbbg BtckugBBS žbbppp žbbbbgš BtckugB SBBgš BtckugBV SBg BuswctgBV SBgš BuswctgBSX `BJ ƒ B ƒ K JtckugK Formatted Output `BJˆ ƒ B ŽBD fb ]B cb ŽDBSYBIˆ K DSYB ]BhqqB ŽD `BJˆ ƒ B ŽBD VNhB ƒždbspuvwk DSPUB ƒžd Jˆ ƒ B ŽBDj G BƒBŽ B ƒ PDK Dj BƒBŽ B ƒ PD 2.10 Rule-Based Reactive System Revisited z Homework `BJƒ BIJŽ ˆ Bˆƒ KBIJJJŽ ˆ Bˆƒ KBSKKK `BJƒ BIJŽ ˆ Bˆƒ KBIJJJŽ ˆ Bˆƒ KBSKKB\ BEI ƒžk JJŽ ˆ Bˆƒ KBSK `BJƒ BIŽ ˆ BIJJJŽ ˆ Bˆƒ KBSKKB\ BEIˆ K JJŽ ˆ Bˆƒ KBSK
11 Exercises z (switch '(a b)) (b a) z (switch '(a b c d) 2 4) (c b a d) z (factorial 3) 6 z (distance '(2 5) '(3 6)) 1.4 z (remove 'b '(a b c b d)) (a c d) z (intersect '(a b b c d) '(c a b b)) (a b c) Explain in detail what ƒž does when it encounters J B KBin the following Lisp session. J ˆ B BJšKBJLBšBšBšKK BBB J B BUK BBB J B K
Thursday, May 11, Funds and what they may do i o r you. Phone or write today.. DONALD A. BURLESON, Representative
96 6 b b K k b b b b k k b b b b b Q K k k k b 3 $6 b K $ b k 6 9 9 3 3 389 3977 b k k z! k b 7 b b " " :? q q b bb j k b 96 5 3 8 ; "! ( 496) 3879 " j b b j k bb b " " k k b b b 9 6 9 6 5 : k k b b b
More informationMinimization of Two-Level Functions
¹±oŽ bž± «b ² ««¼ «± Goals: Minimization of Two-Level Functions Minimize cover cardinality Minimize number of literals PLA implementation: Minimize number of rows Minimize number of transistors --> Minimize
More informationIvOWELL JOURNAL. FOR A BIG CONGRESS.
x 2 2 B X 2 2 Y- B Z x K- - * \ F 2 K» j x 3 zz K - Y K Kx K - ««B* j «K 2 x K! 3 - : 5 j F) % x B F * ( - K 23 x x % F B F * ( K x Y 3 F B j x X j * ; j - zz / - j - ; K: ;? - : - Y : ; j ; -: : - * :
More informationCS 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 informationSymbolic 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 informationFunctional 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 informationCOP4020 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 informationPrinciples 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 informationExtending Pattern Directed Inference Systems. EECS 344 Winter 2008
Extending Pattern Directed Inference Systems EECS 344 Winter 2008 Extending the basic PDIS model How to increase the convenience of the system How to increase the logical power of the system How to increase
More informationAn Explicit-Continuation Metacircular Evaluator
Computer Science (1)21b (Spring Term, 2018) Structure and Interpretation of Computer Programs An Explicit-Continuation Metacircular Evaluator The vanilla metacircular evaluator gives a lot of information
More informationDocumentation 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 informationMore Scheme CS 331. Quiz. 4. What is the length of the list (()()()())? Which element does (car (cdr (x y z))) extract from the list?
More Scheme CS 331 Quiz 1. What is (car ((2) 3 4))? (2) 2. What is (cdr ((2) (3) (4)))? ((3)(4)) 3. What is (cons 2 (2 3 4))? (2 2 3 4) 4. What is the length of the list (()()()())? 4 5. Which element
More information;; definition of function, fun, that adds 7 to the input (define fun (lambda (x) (+ x 7)))
Homework 1 Due 13 September Handout 2 CSC 131: Fall, 2006 6 September Reading 1. Read Mitchell, Chapter 3. 2. The Scheme Tutorial and the Scheme Quick Reference from the Links web page, as needed for the
More informationFunctional 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 informationo w n b a p t i s m by a B a p t i s t m i n i s t e r, t h e P e d o baptist minister,who.se labors previously h e had
55 [ G 5 b b K x «««\ K b «0 ( X K K -Q F F «x b x F «««0«- «7 Q ««K «««xz / 7«b «b «««b K b «««b «x K/ = ( b«k «««K KF K F? xx- -«««- «- b - K- «7 b «b - /«b b qk «z x «««b - &- F «7 «b x G K Q xx Fb
More information1.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 informationLECTURE 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 informationFunctional 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 informationA Brief Introduction to Scheme (II)
A Brief Introduction to Scheme (II) Philip W. L. Fong pwlfong@cs.uregina.ca Department of Computer Science University of Regina Regina, Saskatchewan, Canada Lists Scheme II p.1/29 Lists Aggregate data
More informationUser-defined Functions. Conditional Expressions in Scheme
User-defined Functions The list (lambda (args (body s to a function with (args as its argument list and (body as the function body. No quotes are needed for (args or (body. (lambda (x (+ x 1 s to the increment
More informationCS422 - Programming Language Design
1 CS422 - Programming Language Design Continuation-Passing Style (CPS) Transformation Grigore Roşu Department of Computer Science University of Illinois at Urbana-Champaign 2 On Data Versus Control Context
More informationAn introduction to Scheme
An introduction to Scheme Introduction A powerful programming language is more than just a means for instructing a computer to perform tasks. The language also serves as a framework within which we organize
More informationBindings & Substitution
Bindings & Substitution Even in our simple language, we encounter repeated expressions. 1 {* {+ 4 2} {+ 4 2}} There are several reasons to eliminate duplicated code. It introduces a redundant computation.
More informationFunctional 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 informationCS 342 Lecture 8 Data Abstraction By: Hridesh Rajan
CS 342 Lecture 8 Data Abstraction By: Hridesh Rajan 1 Com S 342 so far So far we have studied: Language design goals, Basic functional programming, Flat recursion over lists, Notion of Scheme procedures
More informationINF4820: 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 informationFunctional 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 informationCS 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 informationChapter 15. Functional Programming Languages
Chapter 15 Functional Programming Languages Copyright 2009 Addison-Wesley. All rights reserved. 1-2 Chapter 15 Topics Introduction Mathematical Functions Fundamentals of Functional Programming Languages
More informationCMPUT 325 : Lambda Calculus Basics. Lambda Calculus. Dr. B. Price and Dr. R. Greiner. 13th October 2004
CMPUT 325 : Lambda Calculus Basics Dr. B. Price and Dr. R. Greiner 13th October 2004 Dr. B. Price and Dr. R. Greiner CMPUT 325 : Lambda Calculus Basics 1 Lambda Calculus Lambda calculus serves as a formal
More informationSummer 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 informationTAIL 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 informationRacket: Macros. Advanced Functional Programming. Jean-Noël Monette. November 2013
Racket: Macros Advanced Functional Programming Jean-Noël Monette November 2013 1 Today Macros pattern-based macros Hygiene Syntax objects and general macros Examples 2 Macros (According to the Racket Guide...)
More informationCS61A 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 information6.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 informationDebugging in LISP. trace causes a trace to be printed for a function when it is called
trace causes a trace to be printed for a function when it is called ;;; a function that works like reverse (defun rev (list) (cons (first (last list)) (rev (butlast list)))) USER: (trace rev) ; note trace
More informationCS 1110: WORKED EXAMPLES REGARDING LOOPS AND INVARIANTS
CS 1110: WORKED EXAMPLES REGARDING LOOPS AND INVARIANTS http://www.cs.cornell.edu/courses/cs1110/2013sp/materials/loop_invariants.pdf D. GRIES, L. LEE, S. MARSCHNER, AND W. WHITE An invariant is, in the
More informationCPS 506 Comparative Programming Languages. Programming Language Paradigm
CPS 506 Comparative Programming Languages Functional Programming Language Paradigm Topics Introduction Mathematical Functions Fundamentals of Functional Programming Languages The First Functional Programming
More informationLanguages and Compiler Design II IR Code Optimization
Languages and Compiler Design II IR Code Optimization Material provided by Prof. Jingke Li Stolen with pride and modified by Herb Mayer PSU Spring 2010 rev.: 4/16/2010 PSU CS322 HM 1 Agenda IR Optimization
More informationChapter 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 informationDiscussion 12 The MCE (solutions)
Discussion 12 The MCE (solutions) ;;;;METACIRCULAR EVALUATOR FROM CHAPTER 4 (SECTIONS 4.1.1-4.1.4) of ;;;; STRUCTURE AND INTERPRETATION OF COMPUTER PROGRAMS ;;;from section 4.1.4 -- must precede def of
More informationCVO103: Programming Languages. Lecture 5 Design and Implementation of PLs (1) Expressions
CVO103: Programming Languages Lecture 5 Design and Implementation of PLs (1) Expressions Hakjoo Oh 2018 Spring Hakjoo Oh CVO103 2018 Spring, Lecture 5 April 3, 2018 1 / 23 Plan Part 1 (Preliminaries):
More informationCSCI Compiler Design
CSCI 565 - Compiler Design Spring 2010 Final Exam - Solution May 07, 2010 at 1.30 PM in Room RTH 115 Duration: 2h 30 min. Please label all pages you turn in with your name and student number. Name: Number:
More informationCSc 520 Principles of Programming Languages
CSc 520 Principles of Programming Languages 9: Scheme Metacircular Interpretation Christian Collberg collberg@cs.arizona.edu Department of Computer Science University of Arizona Copyright c 2005 Christian
More informationFP 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 informationLambda Calculus LC-1
Lambda Calculus LC-1 λ- Calculus History-1 Developed by Alonzo Church during 1930 s-40 s One fundamental goal was to describe what can be computed. Full definition of λ-calculus is equivalent in power
More informationCIS 194: Homework 3. Due Wednesday, February 11, Interpreters. Meet SImPL
CIS 194: Homework 3 Due Wednesday, February 11, 2015 Interpreters An interpreter is a program that takes another program as an input and evaluates it. Many modern languages such as Java 1, Javascript,
More informationThis exam is worth 70 points, or about 23% of your total course grade. The exam contains 15 questions.
CS 61A Final Exam May 16, 2008 Your name login: cs61a This exam is worth 70 points, or about 23% of your total course grade. The exam contains 15 questions. This booklet contains 18 numbered pages including
More informationLambda 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 informationAnnouncement. 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 informationCSSE 304 Assignment #13 (interpreter milestone #1) Updated for Fall, 2018
CSSE 304 Assignment #13 (interpreter milestone #1) Updated for Fall, 2018 Deliverables: Your code (submit to PLC server). A13 participation survey (on Moodle, by the day after the A13 due date). This is
More informationProgramming Languages
Programming Languages Tevfik Koşar Lecture - VIII February 9 th, 2006 1 Roadmap Allocation techniques Static Allocation Stack-based Allocation Heap-based Allocation Scope Rules Static Scopes Dynamic Scopes
More informationLisp 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 information6.001: Structure and Interpretation of Computer Programs
6.001: Structure and Interpretation of Computer Programs Symbols Quotation Relevant details of the reader Example of using symbols Alists Differentiation Data Types in Lisp/Scheme Conventional Numbers
More informationSolution to ECE680 HW3
ECE 680 Solution to HW 3 April 30, 2008 1 Solution to ECE680 HW3 In this homework assignment, we consider the one-link robot manipulator described in Example 5.13 on pp. 256 262 of the text. This system
More informationRecursion & Iteration
Recursion & Iteration York University Department of Computer Science and Engineering 1 Overview Recursion Examples Iteration Examples Iteration vs. Recursion Example [ref.: Chap 5,6 Wilensky] 2 Recursion
More informationFunctional 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 informationNotes 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 informationBest-First Search Minimizing Space or Time. IDA* Save space, take more time
Best-First Search Minimizing Space or Time IDA* Save space, take more time IDA*-1 A* space complexity» What does the space complexity of A* depend upon? IDA*-2 A* space complexity 2» What does the space
More informationCSCE 314 TAMU Fall CSCE 314: Programming Languages Dr. Flemming Andersen. Haskell Basics
1 CSCE 314: Programming Languages Dr. Flemming Andersen Haskell Basics 2 Contents 1. Jump into Haskell: Using ghc and ghci (more detail) 2. Historical Background of Haskell 3. Lazy, Pure, and Functional
More informationProlog. Artificial Intelligence. Lecture 2 Karim Bouzoubaa
Prolog Artificial Intelligence Lecture 2 Karim Bouzoubaa Content Introduction Declarative and logic programming Example Computational model Prolog reasoning Structure of prolog programs Prolog concepts
More informationCommon 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 informationAn 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 informationCS 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 information6.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 informationCS 314 Principles of Programming Languages. Lecture 16
CS 314 Principles of Programming Languages Lecture 16 Zheng Zhang Department of Computer Science Rutgers University Friday 28 th October, 2016 Zheng Zhang 1 CS@Rutgers University Class Information Reminder:
More informationReview: Hoare Logic Rules
Review: Hoare Logic Rules wp(x := E, P) = [E/x] P wp(s;t, Q) = wp(s, wp(t, Q)) wp(if B then S else T, Q) = B wp(s,q) && B wp(t,q) Proving loops correct First consider partial correctness The loop may not
More informationInformatica 3 Syntax and Semantics
Informatica 3 Syntax and Semantics Marcello Restelli 9/15/07 Laurea in Ingegneria Informatica Politecnico di Milano Introduction Introduction to the concepts of syntax and semantics Binding Variables Routines
More informationSymbolic 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 informationCS 11 Ocaml track: lecture 7
CS 11 Ocaml track: lecture 7 Today: Writing a computer language, part 2 Evaluating the AST Environments and scoping Where we're at We've implemented the first part of a language interpreter source code
More informationSymbolic Reasoning. Dr. Neil T. Dantam. Spring CSCI-561, Colorado School of Mines. Dantam (Mines CSCI-561) Symbolic Reasoning Spring / 86
Symbolic Reasoning Dr. Neil T. Dantam CSCI-561, Colorado School of Mines Spring 2019 Dantam (Mines CSCI-561) Symbolic Reasoning Spring 2019 1 / 86 Introduction Definition: Symbolic Reasoning Inference
More informationScheme 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 informationCSCC24 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 informationFall 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 informationCSCE 314 Programming Languages
CSCE 314 Programming Languages Haskell 101 Dr. Hyunyoung Lee 1 Contents 1. Historical Background of Haskell 2. Lazy, Pure, and Functional Language 3. Using ghc and ghci 4. Functions 5. Haskell Scripts
More informationCS 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 informationOpenMP 4.5: Threading, vectorization & offloading
OpenMP 4.5: Threading, vectorization & offloading Michal Merta michal.merta@vsb.cz 2nd of March 2018 Agenda Introduction The Basics OpenMP Tasks Vectorization with OpenMP 4.x Offloading to Accelerators
More informationCS422 - Programming Language Design
1 CS422 - Programming Language Design Elements of Functional Programming Grigore Roşu Department of Computer Science University of Illinois at Urbana-Champaign 2 The two languages that we defined so far
More informationCSCI 3155: Homework Assignment 4
CSCI 3155: Homework Assignment 4 Spring 2012: Due Monday, March 12, 2012 Like last time, find a partner. You will work on this assignment in pairs. However, note that each student needs to submit a write-up
More informationEnvironments
Environments PLAI Chapter 6 Evaluating using substitutions is very inefficient To work around this, we want to use a cache of substitutions. We begin evaluating with no cached substitutions, then collect
More informationMid-Term 2 Grades
Mid-Term 2 Grades 100 46 1 HW 9 Homework 9, in untyped class interpreter: Add instanceof Restrict field access to local class Implement overloading (based on argument count) Due date is the same as for
More informationFunctional Programming - 2. Higher Order Functions
Functional Programming - 2 Higher Order Functions Map on a list Apply Reductions: foldr, foldl Lexical scoping with let s Functional-11, CS5314, Sp16 BGRyder 1 Higher Order Functions Functions as 1st class
More informationbindings (review) Topic 18 Environment Model of Evaluation bindings (review) frames (review) frames (review) frames (review) x: 10 y: #f x: 10
Topic 18 Environment Model of Evaluation Section 3.2 bindings (review) a binding is an association between a name and a Scheme value names: variable names, procedure names formal parameters of procedures
More informationRecursion. Chapter 7
Recursion Chapter 7 Chapter Objectives To understand how to think recursively To learn how to trace a recursive method To learn how to write recursive algorithms and methods for searching arrays To learn
More informationCLIP - A Crytographic Language with Irritating Parentheses
CLIP - A Crytographic Language with Irritating Parentheses Author: Duan Wei wd2114@columbia.edu Yi-Hsiu Chen yc2796@columbia.edu Instructor: Prof. Stephen A. Edwards July 24, 2013 Contents 1 Introduction
More informationCS 360 Programming Languages Interpreters
CS 360 Programming Languages Interpreters Implementing PLs Most of the course is learning fundamental concepts for using and understanding PLs. Syntax vs. semantics vs. idioms. Powerful constructs like
More informationRun Time Environments
Run Time Environments ALSU Textbook Chapter 7.1 7.3 Tsan-sheng Hsu tshsu@iis.sinica.edu.tw http://www.iis.sinica.edu.tw/~tshsu 1 Preliminaries During the execution of a program, the same name in the source
More informationCSE341: Programming Languages Lecture 17 Implementing Languages Including Closures. Dan Grossman Autumn 2018
CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures Dan Grossman Autumn 2018 Typical workflow concrete syntax (string) "(fn x => x + x) 4" Parsing Possible errors / warnings
More informationThe role of semantic analysis in a compiler
Semantic Analysis Outline The role of semantic analysis in a compiler A laundry list of tasks Scope Static vs. Dynamic scoping Implementation: symbol tables Types Static analyses that detect type errors
More information1 Lexical Considerations
Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler
More informationUNIVERSITY OF TORONTO AT MISSISSAUGA April 2006 Examination CSC 324H5 S Instructor: Richard Krueger Duration 3 hours No Aids Allowed
UNIVERSITY OF TORONTO AT MISSISSAUGA April 2006 Examination CSC 324H5 S Instructor: Richard Krueger Duration 3 hours No Aids Allowed Student Number: Last (Family) Name(s): First (Given) Name(s): SOLUTIONS
More informationLecture 13 CIS 341: COMPILERS
Lecture 13 CIS 341: COMPILERS Announcements HW4: OAT v. 1.0 Parsing & basic code generation Due: March 28 th START EARLY! Midterm Exam Grades Available on Gradescope Zdancewic CIS 341: Compilers 2 Midterm
More informationAn Elegant Weapon for a More Civilized Age
An Elegant Weapon for a More Civilized Age Solving an Easy Problem What are the input types? What is the output type? Give example input/output pairs Which input represents the domain of the recursion,
More informationSCHEME The Scheme Interpreter. 2 Primitives COMPUTER SCIENCE 61A. October 29th, 2012
SCHEME COMPUTER SCIENCE 6A October 29th, 202 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, we will eventually
More informationWrite a procedure powerset which takes as its only argument a set S and returns the powerset of S.
Answers to CS61 A Final of May 23, 1997 We repeat the questions; some have typos corrected with respect to the actual exam handed out. Question 1 (5 points): Let us represent a set S of unique expressions,
More informationSCHEME 7. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. October 29, 2015
SCHEME 7 COMPUTER SCIENCE 61A October 29, 2015 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 programs,
More informationCSCI337 Organisation of Programming Languages LISP
Organisation of Programming Languages LISP Getting Started Starting Common Lisp $ clisp i i i i i i i ooooo o ooooooo ooooo ooooo I I I I I I I 8 8 8 8 8 o 8 8 I \ `+' / I 8 8 8 8 8 8 \ `-+-' / 8 8 8 ooooo
More informationModern 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 informationHomework 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 informationProgramming Languages
Programming Languages Lambda Calculus and Scheme CSCI-GA.2110-003 Fall 2011 λ-calculus invented by Alonzo Church in 1932 as a model of computation basis for functional languages (e.g., Lisp, Scheme, ML,
More information