Scheme: Expressions & Procedures
|
|
- Dorcas Morrison
- 5 years ago
- Views:
Transcription
1 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 of Alaska Fairbanks 2017 Glenn G. Chappell
2 Review PL Features: Reflection Reflection in a computer program refers to the ability of the program to deal with its own code at runtime: examining the code, looking at its properties, and modifying it. An important property of a PL is whether, and how well, it supports reflection. The Lisp-family PLs are distinguished by their excellent support for reflection. 31 Mar 2017 CS F331 / CSCE A331 Spring
3 PL Categories: Lisp-Family PLs Background [1/2] In 1958, MIT professor John McCarthy published a mathematical formalism for describing computation. This formalism was written in various was; the most common notation was the Symbolic Expression, or S-expression. An S-expression is either an atom (basically a word), a pair (two S-expressions separated by a dot and enclosed in parentheses), or nil (an empty pair of parentheses). (THIS. (IS. (AN. ((S. (EXPRESSION. ())). ())))) A shorter form uses a parenthesized list of space-separated items. Something like (A. (B. (C. ()))) is written as (A B C). (THIS IS AN (S EXPRESSION)) 31 Mar 2017 CS F331 / CSCE A331 Spring
4 PL Categories: Lisp-Family PLs Background [2/2] An implementation of the evaluation procedure of this formalism, initially written by Dartmouth student Steve Russell, became the programming language Lisp (LISt Processor). S-expressions are the syntax for both code and data in Lisp. 31 Mar 2017 CS F331 / CSCE A331 Spring
5 PL Categories: Lisp-Family PLs Typical Characteristics [1/2] Lisp-family PLs typically have the following characteristics. Simple syntax based on the S-expression. A program is a list of lists. The first item of a list is a function; the rest are its arguments. For example, the C/C++/Java expression (a + 2) * -b would be written as follows in a typical Lisp-family PL: (* (+ a 2) (- b)) Where have we seen this before? Tweak the notation a bit: replace parentheses with braces, separate list items by commas, and place atoms in double quotes. Result: {"*", {"+", "a", "2"}, {"-", "b"}} Where have we seen this before? This was our first stab at an AST representation in Lua. Thus, Lisp source code is a direct representation of its own AST! Source-code syntax and storage format is that of the PLs primary data structures. Types can be checked, and code can be modified & executed at runtime. Support for reflection is excellent. Typical programming styles involve macros: transformations applied to code at runtime. 31 Mar 2017 CS F331 / CSCE A331 Spring
6 PL Categories: Lisp-Family PLs Typical Characteristics [2/2] Typical characteristics of Lisp-family PLs (cont d): Typing is dynamic, implicit, and structural (duck typing). There is very good support for functional programming: first-class functions, higher-order functions, etc. But mutable data is allowed. The PL is extensible. Execution can be either interactive (REPL) or via previously compiled code. Accomplished Lisp programmers tend to be insufferably fond of Lisp. ( We can already do that in Lisp. <smirk> ) But perhaps they re onto something. 31 Mar 2017 CS F331 / CSCE A331 Spring
7 Introduction to Scheme History [1/2] As with many PLs, the early history of Lisp was one of everincreasing complexity. As a result, the Common Lisp standard is huge, including exceptions, an object system, etc. Perhaps as a reaction to this, a Lisp-family PL called Scheme was created at the MIT AI Lab around 1970, by Guy Steele and Gerald Sussman. In contrast to Common Lisp, Scheme follows a minimalist design philosophy, with a small, simple core and versatile tools for extending the PL. 31 Mar 2017 CS F331 / CSCE A331 Spring
8 Introduction to Scheme History [2/2] Scheme follows somewhat different conventions from traditional Lisp for the evaluation of functions. Thus, while some say Scheme is a dialect of Lisp, others emphatically deny this. But Scheme clearly belongs in the Lisp family of PLs. Scheme has been standardized in a series of standards documents. The most recent (R7RS) was released in A version of Scheme called PLT Scheme (named for the Rice University Programming Languages Team) was first released in This was renamed as Racket in Distributed with Racket is a simple IDE called DrRacket, which runs on all major platforms. This is the Scheme implementation we will be using. 31 Mar 2017 CS F331 / CSCE A331 Spring
9 Introduction to Scheme Characteristics Introduction Scheme is a Lisp-family PL with a minimalist design philosophy. Scheme code consists of parenthesized lists, which may contain atoms or other lists. List items are separated by space; blanks and newlines between list items are treated the same. (define (hello-world) (begin (display "Hello, world!") (newline) ) ) When a list is evaluated, the first item should be a procedure (think function ); the remaining items are its arguments. 31 Mar 2017 CS F331 / CSCE A331 Spring
10 Introduction to Scheme Characteristics Type System [1/2] The type system of Scheme is similar to that of Lua. Typing is dynamic. Typing is implicit. Type annotations are generally not used. Type checking is structural. Duck typing is used. There is a high level of type safety: operations on invalid types are not allowed, and implicit type conversions are rare. There is a fixed set of types. Lua s fixed set of types includes only 8 types, while Scheme has 36. We look at some of these next. 31 Mar 2017 CS F331 / CSCE A331 Spring
11 Introduction to Scheme Characteristics Type System [2/2] Two heavily used types are pair and null, which are mostly used to construct lists. Values of all other types are atoms. Here are a few of these: Booleans. Values are #t (true) and #f (false). Strings. Enclosed in double quotes: "This is a string." Characters. For example, here is the 'a' character: #\a Symbols. A symbol is an identifier: abc x a-long-symbol Number types. There are seven of these, including arbitrarily large integers (like Haskell s Integer), floating-point numbers, exact rational numbers, and complex numbers. Procedure types. A procedure is what we would call a first-class function. A procedure may be bound to a name (a symbol), or it may be unnamed. There are actually six procedure types, but we will not need to distinguish between these. 31 Mar 2017 CS F331 / CSCE A331 Spring
12 Introduction to Scheme Characteristics Flow of Control Scheme has no special syntax for flow of control. Instead, flow-ofcontrol constructs are procedures. Here is some Lua code and more or less equivalent Scheme code. if x == 3 then -- Lua io.write("three") else io.write("other") end (if (= x 3) ; Scheme "if" is a procedure (display "three") (display "other") ) 31 Mar 2017 CS F331 / CSCE A331 Spring
13 Introduction to Scheme Characteristics Miscellaneous As with Lua, Scheme local variables are lexically scoped. Scheme globals have dynamic scope. Scheme has very good support for functional programming. It is not a pure functional PL; it does allow for mutable data. Like all Lisp-family PLs, the syntax and storage format of code is the same as that of the language s primary data structure. Thus, it is natural to manipulate code at runtime. Such code can be executed as part of the same runtime. Thus, Scheme has excellent support for reflection. 31 Mar 2017 CS F331 / CSCE A331 Spring
14 Introduction to Scheme Build & Execution The standard filename suffix for Scheme source files is.scm. Scheme allows for interactive execution or compiled executables. We will not be doing the latter. We will execute Scheme using an IDE called DrRacket. The upper part of the DrRacket window is a source-code editor, with the usual open-save interface. The first line of the code in this window should always be as follows: #lang scheme The lower part of the Window is a REPL. Type in Scheme code to execute. Pressing the Run button executes all code in the upper window. Thereafter, symbols defined in that code may be used in the REPL. 31 Mar 2017 CS F331 / CSCE A331 Spring
15 Scheme: Expressions & Procedures General Syntax We have seen what Scheme code looks like: parenthesized lists of lists, with items separated by space. Many special characters are legal in symbols. In addition: Strings are surrounded by double quotes. A leading single quote suppresses evaluation. Scheme has three kinds of comments. A semicolon (;) begins a single-line comment. Multiline comments: # # Comment out a single expression: #;EXPR #;(This code is commented (out)) (display "But this is not.") 31 Mar 2017 CS F331 / CSCE A331 Spring
16 Scheme: Expressions & Procedures Expressions Evaluation [1/2] Like Haskell, Scheme code consists largely of expressions. An expression can be: An atom. A list whose first item evaluates to a procedure. To evaluate a list, Scheme begins by evaluating its first item. This should result in a procedure. Normally, the remaining arguments are then evaluated. The results of these evaluations are passed to the procedure as its arguments. For some special procedures, the remaining arguments are not evaluated. 31 Mar 2017 CS F331 / CSCE A331 Spring
17 Scheme: Expressions & Procedures Expressions Evaluation [2/2] For example, + is a symbol. It evaluates to a procedure that takes zero or more numeric parameters and returns their sum. Informally, we say that + is a procedure. > (+ 2 7) 9 > ( ) 29 Some procedures can take a varying number of parameters. Symbols -, *, and / are similar. > (* (+ 3 5) (- 7 3) ; Like (3 + 5) * (7 3) 32 > (* 2 (/ 15 3)) Mar 2017 CS F331 / CSCE A331 Spring
18 Scheme: Expressions & Procedures Expressions Operators [1/2] Scheme does not distinguish between operators and other symbols. Nothing is infix. Scheme uses +, -, *, and / for the basic arithmetic operations. But the division operator might not do what you expect. > (/ 4 2) 2 > (/ 4 6) 2/3 > (/ 2/3 4) 1/6 > (+ 1/5 0.7) 0.9 An exact rational number A real (floating-point) number, which, as usual with floating-point, is inexact. Implicit type conversions: integer rational real complex. 31 Mar 2017 CS F331 / CSCE A331 Spring
19 Scheme: Expressions & Procedures Expressions Operators [2/2] The numeric comparison operators: = < <= > >= There is no inequality operator! Logical operations: and or not > (= 1 2) #f > (not (= 1 2)) #t > (and (> 4 1) (<= 5 2)) #f There are several different kinds of equality in Scheme. Use the above comparison operators only with numbers. 31 Mar 2017 CS F331 / CSCE A331 Spring
20 Scheme: Expressions & Procedures Lists [1/2] Two heavily used procedures are car and cdr. Each takes a pair. car returns the first item of the pair. cdr returns the second. Thus, for a nonempty list, car returns the first item, while cdr returns a list of the remaining items. > (car '( )) 5 > (cdr '( )) (4 2 7) A single quote suppresses evaluation. We do not want to treat 5 as a procedure, passing 4, 2, 7 as its arguments. We want the list. cons constructs a pair. We can use it to construct a list from an item and a list, like : in Haskell. > (cons 5 '(4 2 7)) ( ) 31 Mar 2017 CS F331 / CSCE A331 Spring
21 Scheme: Expressions & Procedures Lists [2/2] It is common to use combinations of car & cdr. For example, (car (cdr x)) returns the second item of list x. > (car (cdr '( ))) ; Second item 4 > (car (cdr (cdr '( )) ; Third item 2 All such combinations, up to 5 car/cdr applications, are implemented as predefined functions. > (cadr '( )) ; Second item 4 > (caddr '( )) ; Third item 2 31 Mar 2017 CS F331 / CSCE A331 Spring
22 Scheme: Expressions & Procedures Predicates Recall: a predicate is a function returning a boolean. It answers a yes/no question about its argument(s). It is traditional for the name of a Scheme predicate to end in a question mark. Here are some type-checking predicates. Each takes a single parameter, which can be of any type. number? Returns true (#t) if its argument is a number, otherwise false (#f). null? Returns true if its argument is null (an empty list). pair? Returns true if its argument is a pair. Thus, if the argument is a list, then it returns true if the list is nonempty. If neither null? nor pair? returns true for a value, then the value is an atom. > (number? 3) #t > (number? +) #f 31 Mar 2017 CS F331 / CSCE A331 Spring
23 Scheme: Expressions & Procedures Binding Bind a symbol to a value with define. > (define abc (+ 5 3)) > abc 8 > (* abc (- abc 5)) 24 > (define xyz +) > (xyz 3 4) 7 31 Mar 2017 CS F331 / CSCE A331 Spring
24 Scheme: Expressions & Procedures Defining Procedures [1/3] We can also define new procedures with define. The first argument is a list that is essentially a picture of a call to our new procedure. The second argument is an expression giving the code for the procedure; this code is not evaluated until the procedure is called. Parameters are bound locally. > (define (sqr x) (* x x)) > (sqr 6) 36 > (define (not= a b) (not (= a b))) > (not= 1 3) #t > (not= (+ 1 2) 3) #f 31 Mar 2017 CS F331 / CSCE A331 Spring
25 Scheme: Expressions & Procedures Defining Procedures [2/3] if is a three-parameter procedure. (if COND THEN-EXPR ELSE-EXPR) The above evaluates COND. If this evaluates to anything other than #f, then it evaluates THEN-EXPR and returns the result; otherwise, it evaluates ELSE-EXPR and returns the result. > (if (= 3 3) "yes" "NO") "yes" 31 Mar 2017 CS F331 / CSCE A331 Spring
26 Scheme: Expressions & Procedures Defining Procedures [3/3] A recursive call is done by using the word being defined inside its body. And now we have the tools to write all kinds of things See proc.scm. 31 Mar 2017 CS F331 / CSCE A331 Spring
Scheme: Data. CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, April 3, Glenn G.
Scheme: Data CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, April 3, 2017 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks ggchappell@alaska.edu
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 informationScheme: Strings Scheme: I/O
Scheme: Strings Scheme: I/O CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Wednesday, April 5, 2017 Glenn G. Chappell Department of Computer Science University of
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 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 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 informationHaskell: Lists. CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Friday, February 24, Glenn G.
Haskell: Lists CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Friday, February 24, 2017 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks
More informationCOP4020 Programming Assignment 1 - Spring 2011
COP4020 Programming Assignment 1 - Spring 2011 In this programming assignment we design and implement a small imperative programming language Micro-PL. To execute Mirco-PL code we translate the code to
More informationFunctional 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 informationScheme 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 informationFunctional programming in LISP
Programming Languages Week 4 Functional programming in LISP College of Information Science and Engineering Ritsumeikan University review of part 3 enumeration of dictionaries you receive a sequence of
More informationPL Categories: Functional PLs Introduction to Haskell Haskell: Functions
PL Categories: Functional PLs Introduction to Haskell Haskell: Functions CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Wednesday, February 22, 2017 Glenn G. Chappell
More informationScheme. 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 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 informationAnnouncements. The current topic: Scheme. Review: BST functions. Review: Representing trees in Scheme. Reminder: Lab 2 is due on Monday at 10:30 am.
The current topic: Scheme! Introduction! Object-oriented programming: Python Functional programming: Scheme! Introduction! Numeric operators, REPL, quotes, functions, conditionals! Function examples, helper
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 informationCSc 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 informationCSC 533: Programming Languages. Spring 2015
CSC 533: Programming Languages Spring 2015 Functional programming LISP & Scheme S-expressions: atoms, lists functional expressions, evaluation, define primitive functions: arithmetic, predicate, symbolic,
More information11/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 informationThoughts on Assignment 4 Haskell: Flow of Control
Thoughts on Assignment 4 Haskell: Flow of Control CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, February 27, 2017 Glenn G. Chappell Department of Computer
More informationThe Typed Racket Guide
The Typed Racket Guide Version 5.3.6 Sam Tobin-Hochstadt and Vincent St-Amour August 9, 2013 Typed Racket is a family of languages, each of which enforce
More informationIntroduction 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 informationIntroduction 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 informationIntroduction to Typed Racket. The plan: Racket Crash Course Typed Racket and PL Racket Differences with the text Some PL Racket Examples
Introduction to Typed Racket The plan: Racket Crash Course Typed Racket and PL Racket Differences with the text Some PL Racket Examples Getting started Find a machine with DrRacket installed (e.g. the
More informationTyped Racket: Racket with Static Types
Typed Racket: Racket with Static Types Version 5.0.2 Sam Tobin-Hochstadt November 6, 2010 Typed Racket is a family of languages, each of which enforce that programs written in the language obey a type
More informationWriting a Lexer. CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, February 6, Glenn G.
Writing a Lexer CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, February 6, 2017 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks
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 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 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 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 informationCSE 413 Languages & Implementation. Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341)
CSE 413 Languages & Implementation Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341) 1 Goals Representing programs as data Racket structs as a better way to represent
More informationScheme Quick Reference
Scheme Quick Reference COSC 18 Winter 2003 February 10, 2003 1 Introduction This document is a quick reference guide to common features of the Scheme language. It is by no means intended to be a complete
More informationSpring 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 informationWriting an Interpreter Thoughts on Assignment 6
Writing an Interpreter Thoughts on Assignment 6 CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, March 27, 2017 Glenn G. Chappell Department of Computer Science
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 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 informationLisp. 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 informationSCHEME 8. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. March 23, 2017
SCHEME 8 COMPUTER SCIENCE 61A March 2, 2017 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 informationPrinciples of Programming Languages Topic: Functional Programming Professor L. Thorne McCarty Spring 2003
Principles of Programming Languages Topic: Functional Programming Professor L. Thorne McCarty Spring 2003 CS 314, LS, LTM: Functional Programming 1 Scheme A program is an expression to be evaluated (in
More informationFunctional 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 informationScheme Quick Reference
Scheme Quick Reference COSC 18 Fall 2003 This document is a quick reference guide to common features of the Scheme language. It is not intended to be a complete language reference, but it gives terse summaries
More informationFall 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 informationWelcome to CS 135 (Winter 2018)
Welcome to CS 135 (Winter 2018) Instructors: Sandy Graham, Paul Nijjar Other course personnel: see website for details ISAs (Instructional Support Assistants) IAs (Instructional Apprentices) ISC (Instructional
More informationChapter 15 Functional Programming Languages
Chapter 15 Functional Programming Languages Fundamentals of Functional Programming Languages Introduction to Scheme A programming paradigm treats computation as the evaluation of mathematical functions.
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 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 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 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 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 informationOrganization 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 informationFall 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 informationConcepts 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 informationIntro. Scheme Basics. scm> 5 5. scm>
Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if
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 informationProject 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 informationWelcome to CS 135 (Fall 2018) Themes of the course. Lectures. cs135/
Welcome to CS 135 (Fall 2018) Instructors: Byron Weber Becker, Charles Clarke, Gord Cormack, Robert Hackman, Kevin Lanctot, Paul Nijjar, Adrian Reetz Other course personnel: see website for details ISAs
More informationThe SPL Programming Language Reference Manual
The SPL Programming Language Reference Manual Leonidas Fegaras University of Texas at Arlington Arlington, TX 76019 fegaras@cse.uta.edu February 27, 2018 1 Introduction The SPL language is a Small Programming
More informationJME Language Reference Manual
JME Language Reference Manual 1 Introduction JME (pronounced jay+me) is a lightweight language that allows programmers to easily perform statistic computations on tabular data as part of data analysis.
More informationA Small Interpreted Language
A Small Interpreted Language What would you need to build a small computing language based on mathematical principles? The language should be simple, Turing equivalent (i.e.: it can compute anything that
More informationINF4820: 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 informationThe PCAT Programming Language Reference Manual
The PCAT Programming Language Reference Manual Andrew Tolmach and Jingke Li Dept. of Computer Science Portland State University September 27, 1995 (revised October 15, 2002) 1 Introduction The PCAT language
More informationClass 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 informationSOFTWARE ARCHITECTURE 6. LISP
1 SOFTWARE ARCHITECTURE 6. LISP Tatsuya Hagino hagino@sfc.keio.ac.jp slides URL https://vu5.sfc.keio.ac.jp/sa/ 2 Compiler vs Interpreter Compiler Translate programs into machine languages Compilers are
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 informationIntroduction 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 information4/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 informationProgramming Languages
Programming Languages Tevfik Koşar Lecture - XIII March 2 nd, 2006 1 Roadmap Functional Languages Lambda Calculus Intro to Scheme Basics Functions Bindings Equality Testing Searching 2 1 Functional Languages
More informationHonu. Version November 6, 2010
Honu Version 5.0.2 November 6, 2010 Honu is a family of languages built on top of Racket. Honu syntax resembles Java. Like Racket, however, Honu has no fixed syntax, because Honu supports extensibility
More informationReasoning About Programs Panagiotis Manolios
Reasoning About Programs Panagiotis Manolios Northeastern University March 22, 2012 Version: 58 Copyright c 2012 by Panagiotis Manolios All rights reserved. We hereby grant permission for this publication
More information15 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 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 informationIntroduction 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 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 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 informationRacket. 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 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 informationCSE 341 Section Handout #6 Cheat Sheet
Cheat Sheet Types numbers: integers (3, 802), reals (3.4), rationals (3/4), complex (2+3.4i) symbols: x, y, hello, r2d2 booleans: #t, #f strings: "hello", "how are you?" lists: (list 3 4 5) (list 98.5
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 informationLecture #24: Programming Languages and Programs
Lecture #24: Programming Languages and Programs A programming language is a notation for describing computations or processes. These range from low-level notations, such as machine language or simple hardware
More informationEvaluating Scheme Expressions
Evaluating Scheme Expressions How Scheme evaluates the expressions? (procedure arg 1... arg n ) Find the value of procedure Find the value of arg 1 Find the value of arg n Apply the value of procedure
More informationIntroduction to Syntax Analysis Recursive-Descent Parsing
Introduction to Syntax Analysis Recursive-Descent Parsing CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Friday, February 10, 2017 Glenn G. Chappell Department of
More informationLecture 09: Data Abstraction ++ Parsing is the process of translating a sequence of characters (a string) into an abstract syntax tree.
Lecture 09: Data Abstraction ++ Parsing Parsing is the process of translating a sequence of characters (a string) into an abstract syntax tree. program text Parser AST Processor Compilers (and some interpreters)
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 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 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 informationFull file at
Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class
More informationTypescript on LLVM Language Reference Manual
Typescript on LLVM Language Reference Manual Ratheet Pandya UNI: rp2707 COMS 4115 H01 (CVN) 1. Introduction 2. Lexical Conventions 2.1 Tokens 2.2 Comments 2.3 Identifiers 2.4 Reserved Keywords 2.5 String
More informationCSE 341, Autumn 2015, Ruby Introduction Summary
CSE 341, Autumn 2015, Ruby Introduction Summary Disclaimer: This lecture summary is not necessarily a complete substitute for atting class, reading the associated code, etc. It is designed to be a useful
More informationCS 3360 Design and Implementation of Programming Languages. Exam 1
1 Spring 2017 (Thursday, March 9) Name: CS 3360 Design and Implementation of Programming Languages Exam 1 This test has 8 questions and pages numbered 1 through 7. Reminders This test is closed-notes and
More informationIntroduction to Functional Programming in Racket. CS 550 Programming Languages Jeremy Johnson
Introduction to Functional Programming in Racket CS 550 Programming Languages Jeremy Johnson 1 Objective To introduce functional programming in racket Programs are functions and their semantics involve
More information1 of 5 5/11/2006 12:10 AM CS 61A Spring 2006 Midterm 2 solutions 1. Box and pointer. Note: Please draw actual boxes, as in the book and the lectures, not XX and X/ as in these ASCII-art solutions. Also,
More informationFunctional 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 informationExample Scheme Function: equal
ICOM 4036 Programming Languages Functional Programming Languages Mathematical Functions Fundamentals of Functional Programming Languages The First Functional Programming Language: LISP Introduction to
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 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 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 informationSymbolic Computation
Symbolic Computation Principles of Programming Languages https://lambda.mines.edu 1 What questions did you have on the reading? Can your group members answer, or you can ask me. 2 Define symbolic computation
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 informationThese notes are intended exclusively for the personal usage of the students of CS352 at Cal Poly Pomona. Any other usage is prohibited without
These notes are intended exclusively for the personal usage of the students of CS352 at Cal Poly Pomona. Any other usage is prohibited without previous written authorization. 1 2 The simplest way to create
More informationFundamentals of Artificial Intelligence COMP221: Functional Programming in Scheme (and LISP)
Fundamentals of Artificial Intelligence COMP221: Functional Programming in Scheme (and LISP) Prof. Dekai Wu Department of Computer Science and Engineering The Hong Kong University of Science and Technology
More information