A Brief Introduction to Scheme (I)
|
|
- Silvia Dennis
- 6 years ago
- Views:
Transcription
1 A Brief Introduction to Scheme (I) Philip W. L. Fong Department of Computer Science University of Regina Regina, Saskatchewan, Canada
2 Scheme Scheme I p.1/44
3 Scheme: Feature Set A small dialect of Lisp Support symbolic list processing Garbage collected Functional (although not purely functional) Better than Lisp... first-class procedures tail-call optimization continuations user-defined syntactic extensions the first Lisp dialect to support lexical scoping best for building sophisticated interpreters Scheme I p.2/44
4 Scheme: What s the Big Deal? Why learn about functional programming with a Lisp dialect... Python has lambda expressions, etc see also Ruby XSLT is functional its ancester DSSSL is a Scheme dialect Scheme and Lisp are popular extension languages Emacs: a scriptable UNIX editor Sawfish: an scriptable X11-based window manager Guile: the GNU extension language Scheme I p.3/44
5 Scheme: What s the Big Deal? Why learn about functional programming with a Lisp dialect... Lisp is worth learning for the profound enlightenment experience you will have when you finally get it; that experience will make you a better programmer for the rest of your days, even if you never actually use Lisp itself a lot. Eric Raymond How To Become a Hacker Scheme I p.4/44
6 Scheme: What s the Big Deal? Why learn about functional programming with a Lisp dialect... MIT teaches Scheme to their 1st-year CS students Waterloo is following suit SFU is beginning to teach Python to their 1st-year CS students because it helps them to learn functional programming concepts such as lambda expressions and higher-order functions. Scheme I p.5/44
7 Scheme: Standardization ANSI/IEEE standard The Revised 5 Report on the Algorithmic Language Scheme [R 5 RS] Scheme I p.6/44
8 Interacting with Scheme Scheme I p.7/44
9 The Scheme REPL Scheme prompt: > Scheme I p.8/44
10 The Scheme REPL Scheme prompt: > (* 2 (cos 0) (+ 4 6)) Scheme I p.8/44
11 The Scheme REPL Scheme prompt: > (* 2 (cos 0) (+ 4 6)) 20 Scheme I p.8/44
12 The Scheme REPL Scheme prompt: > (* 2 (cos 0) (+ 4 6)) 20 The read-evaluate-print loop (REPL): loop read an expression evaluate the expression print the result of evaluation end loop Evaluation: expression evaluate value Scheme I p.8/44
13 Scheme Syntax Let s examine the example in details: > (* 2 (cos 0) (+ 4 6)) 20 Scheme I p.9/44
14 Scheme Syntax Let s examine the example in details: > (* 2 (cos 0) (+ 4 6)) 20 constants: 0, 2, 4, 6 identifiers: cos, +, * structured forms: (...) Brackets are not for grouping! In C/C++, ((1)) is the same as 1 In Scheme, ((1)) is NOT 1 Brackets are for delimiting structured forms. procedure application: (proc arg 1... arg n ) + : name of the addition procedure case-insensitive: (cos 0) (COS 0) Scheme I p.9/44
15 Order of Evaluation Order of Evaluation: When there are multiple subexpressions, which subexpression should be evaluated first? Applicative Order: (proc arg 1... arg n ) 1. evaluate arg 1,..., arg n 2. evaluate proc 3. apply proc to arg 1,..., arg n Scheme I p.10/44
16 Numeric Procedures Procedure Meaning (+ x 1... x n ) The sum of x 1,..., x n (* x 1... x n ) The product of x 1,..., x n (- x y) Subtract y from x (- x) Minus x (/ x y) Divide x by y (max x 1... x n ) The maximum of x 1,..., x n (min x 1... x n ) The minimum of x 1,..., x n (sqrt x) The square root of x (abs x) The absolute value of x Scheme I p.11/44
17 Exercise Look up from [TSPL3] Chapter 6 the answers to the following questions: What procedure computes x n? What is the difference between the procedures remainder and modulo? Scheme I p.12/44
18 Scheme Programs Scheme I p.13/44
19 lambda Expressions An anonymous procedure: (lambda (x) (* x 2)) (lambda...) - a name-less procedure (x) - parameter list (* x 2) - procedure body Applying the procedure: > ((lambda (x) (* x 2)) 3) 6 The value of a procedure application is obtained by 1. substituting the actual arguments for the formal parameters in the procedure body 2. evaluating the procedure body Scheme I p.14/44
20 Top-Level Definitions > (define y 3) Scheme I p.15/44
21 Top-Level Definitions > (define y 3) > y 3 Scheme I p.15/44
22 Top-Level Definitions > (define y 3) > y 3 > (define double (lambda (x) (* x 2))) Scheme I p.15/44
23 Top-Level Definitions > (define y 3) > y 3 > (define double (lambda (x) (* x 2))) > (double 3) 6 Scheme I p.15/44
24 Top-Level Definitions > (define y 3) > y 3 > (define double (lambda (x) (* x 2))) > (double 3) 6 > (double (double 3)) 12 Scheme I p.15/44
25 Storing Programs in Files Demonstration Edit program Syntax-check program Run program Scheme I p.16/44
26 Functional Programming Scheme I p.17/44
27 Imperative Programming Mutable global state assignment statements modify variable bindings Command = state transformer state 1 command state 2 Program = sequence of commands Scheme I p.18/44
28 Functional Programming No side effect allowed No assignment statement! Every expression denotes a unique value: expression evaluate value Referential transparency variable bindings do not mutate evaluating an expression always yields the same value Scheme I p.19/44
29 The Functional Fragment of Scheme Scheme supports both the imperative and functional paradigm of programming In the first half of the course, we focus on the functional fragement of Scheme. i.e., programming with expressions that do not produce side effects Scheme I p.20/44
30 Conditional Expressions Scheme I p.21/44
31 Boolean Values Boolean values: #t, #f Anything that is not #f is considered true. A procedure that returns a boolean value is called a predicate. Scheme I p.22/44
32 Example: absolute-value abs(x) = { x if x < 0 x otherwise (define absolute-value (lambda (x) (if (negative? x) (- x) x))) Scheme I p.23/44
33 Conditional Form if (if test-expression true-expression false-expression) 1. Evaluate test-expression. 2. If test-expression evaluates to true then evaluate true-expression and return its value. 3. Otherwise, evaluate false-expression and return its value. Scheme I p.24/44
34 Numeric Predicates Predicate (zero? x) (positive? x) (negative? x) (even? x) (odd? x) Meaning x is zero x is positive x is negative x is even x is odd Scheme I p.25/44
35 Relational Predicates Predicate Meaning (= x y) x is equal to y (< x y) x is less than y (< x y) x is greater than y (<= x y) x is no greater than y (>= x y) x is no less than y Scheme I p.26/44
36 Type Predicates Predicate (number? x) (boolean? x) Meaning x is a number x is a Boolean value (i.e., #t, #f) Scheme I p.27/44
37 Example: sign sign(x) = (define sign (lambda (x) (cond ((positive? x) 1) ((zero? x) 0) (else -1)))) 1 if x > 0 0 if x = 0 1 otherwise Scheme I p.28/44
38 Conditional Form cond (cond (test 1 expr 1 ) (test 1 expr 2 )... (test n expr n ) (else default)) 1. Evaluate test 1, test 2,..., test n in the order they appear. 2. If some test i evaluates to true, then stop evaluating the rest of the test expressions, but instead evaluate expr i and return its value. 3. Otherwise, evaluate default and return its value. Scheme I p.29/44
39 More Conditional Forms Forms (or x 1... x n ) (and x 1... x n ) (not x) Meaning Logical or Logical and Logical negation These are not procedures. Example: (or x 1... x n ) Evaluate x 1,..., x n in the order they appear If any of the arguments evaluates to true, return true rightaway without evaluating the rest of the arguments. Otherwise, return #f. Scheme I p.30/44
40 Exercise Rewrite (not x) into an equivalent expression using only the if form. Rewrite (and x 1... x n ) into an equivalent expression using only the cond form. The definition of and in terms of cond is only an approximation. Check out [TSPL3] Sect. 5.3 to see why. Scheme I p.31/44
41 Equational Reasoning Scheme I p.32/44
42 Equational Reasoning We grow up knowing equational reasoning by heart: (1 + 2) (3 4) = 3 (3 4) = 3 1 = 3 Because of referential transparency, the behavior of functional programs can be understood using equational reasoning! Scheme I p.33/44
43 Example: double (double (double 3)) = (double ((lambda (x) (* x 2)) 3)) = (double (* 3 2)) = (double 6) = ((lambda (x) (* x 2)) 6) = (* 6 2) = 12 Scheme I p.34/44
44 Example: absolute-value (absolute-value -3) = ((lambda (x) (if (negative? x) (- x) x)) -3) = (if (negative? -3) (- -3) -3) = (if #t (- -3) -3) = (- -3) = 3 Scheme I p.35/44
45 Recursion Scheme I p.36/44
46 Recursion vs Iteration In imperative programming languages, repetition can be achieved by iterative constructs such as for or while. In functional programming languages, repetition is mainly achieved by recursion. Scheme I p.37/44
47 Example: triangular (1) triangular(n) = n { 1 if n = 1 = n + triangular(n 1) otherwise (define triangular (lambda (n) (if (= n 1) 1 (+ n (triangular (- n 1)))))) Scheme I p.38/44
48 Example: triangular (2) > (trace triangular) > (triangular 3) (triangular 3) (triangular 2) (triangular 1) > (untrace triangular) Scheme I p.39/44
49 Example: triangular (3) (triangular 3) = ((lambda (n) (if (= n 1) 1 (+ n (triangular (- n 1))))) 3) = (if (= 3 1) 1 (+ 3 (triangular (- 3 1)))) = (if #f 1 (+ 3 (triangular (- 3 1)))) = (+ 3 (triangular (- 3 1))) = (+ 3 (triangular 2)) = (+ 3 (if (= 2 1) 1 (+ 2 (triangular (- 2 1))))) = (+ 3 (+ 2 (triangular (- 2 1)))) = (+ 3 (+ 2 (triangular 1))) = (+ 3 (+ 2 (if (= 1 1) 1 (+ 1 (triangular (- 1 1)))))) = (+ 3 (+ 2 1)) = (+ 3 3) = 6 Scheme I p.40/44
50 Example: power (1) x n = { 1 if n = 0 x x n 1 if n > 0 (define power (lambda (x n) (if (zero? n) 1 (* x (power x (- n 1)))))) Scheme I p.41/44
51 Example: power (2) > (power 2 4) (power 2 4) (power 2 3) (power 2 2) (power 2 1) (power 2 0) Scheme I p.42/44
52 Exercise Use equational reasoning to trace the execution of (power 2 4). Scheme I p.43/44
53 Lecture Summary This lecture and the next cover [TSPL3] Chap In this lecture... REPL the numeric fragment of Scheme functional programming with Scheme equational reasoning lambda expression top-level definition Boolean values conditional forms simple examples of recursion Scheme I p.44/44
A 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 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 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 informationModule 10: Imperative Programming, Modularization, and The Future
Module 10: Imperative Programming, Modularization, and The Future If you have not already, make sure you Read How to Design Programs Sections 18. 1 CS 115 Module 10: Imperative Programming, Modularization,
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 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 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 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 Fundamentals of Functional Programming Languages Introduction to Scheme A programming paradigm treats computation as the evaluation of mathematical functions.
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 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 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 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 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 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 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 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 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. 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 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 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 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 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 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 informationBasic Scheme February 8, Compound expressions Rules of evaluation Creating procedures by capturing common patterns
Basic Scheme February 8, 2007 Compound expressions Rules of evaluation Creating procedures by capturing common patterns Previous lecture Basics of Scheme Expressions and associated values (or syntax and
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 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 informationConcepts of Programming Languages
Concepts of Programming Languages Lecture 15 - Functional Programming Patrick Donnelly Montana State University Spring 2014 Patrick Donnelly (Montana State University) Concepts of Programming Languages
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 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 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 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 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 informationFunctional abstraction. What is abstraction? Eating apples. Readings: HtDP, sections Language level: Intermediate Student With Lambda
Functional abstraction Readings: HtDP, sections 19-24. Language level: Intermediate Student With Lambda different order used in lecture section 24 material introduced much earlier sections 22, 23 not covered
More informationFunctional abstraction
Functional abstraction Readings: HtDP, sections 19-24. Language level: Intermediate Student With Lambda different order used in lecture section 24 material introduced much earlier sections 22, 23 not covered
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 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 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 informationQuick announcement. Midterm date is Wednesday Oct 24, 11-12pm.
Quick announcement Midterm date is Wednesday Oct 24, 11-12pm. The lambda calculus = ID (λ ID. ) ( ) The lambda calculus (Racket) = ID (lambda (ID) ) ( )
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 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 informationComp 411 Principles of Programming Languages Lecture 7 Meta-interpreters. Corky Cartwright January 26, 2018
Comp 411 Principles of Programming Languages Lecture 7 Meta-interpreters Corky Cartwright January 26, 2018 Denotational Semantics The primary alternative to syntactic semantics is denotational semantics.
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 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 informationCS115 - Module 9 - filter, map, and friends
Fall 2017 Reminder: if you have not already, ensure you: Read How to Design Programs, Intermezzo 3 (Section 18); Sections 19-23. Abstraction abstraction, n. 3a.... The process of isolating properties or
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 informationIntroduction to Concepts in Functional Programming. CS16: Introduction to Data Structures & Algorithms Spring 2017
Introduction to Concepts in Functional Programming CS16: Introduction to Data Structures & Algorithms Spring 2017 Outline Functions State Functions as building blocks Higher order functions Map Reduce
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 informationData Abstraction. An Abstraction for Inductive Data Types. Philip W. L. Fong.
Data Abstraction An Abstraction for Inductive Data Types Philip W. L. Fong pwlfong@cs.uregina.ca Department of Computer Science University of Regina Regina, Saskatchewan, Canada Introduction This lecture
More informationModule 8: Local and functional abstraction
Module 8: Local and functional abstraction Readings: HtDP, Intermezzo 3 (Section 18); Sections 19-23. We will cover material on functional abstraction in a somewhat different order than the text. We will
More informationRuby: Introduction, Basics
Ruby: Introduction, Basics Computer Science and Engineering College of Engineering The Ohio State University Lecture 4 Ruby vs Java: Similarities Imperative and object-oriented Classes and instances (ie
More informationScheme: 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 informationThe purpose of this lesson is to familiarize you with the basics of Racket (a dialect of Scheme). You will learn about
Lesson 0.4 Introduction to Racket Preliminaries The purpose of this lesson is to familiarize you with the basics of Racket (a dialect of Scheme). You will learn about Expressions Numbers, Booleans, and
More informationChapter 15. Functional Programming Languages
Chapter 15 Functional Programming Languages Chapter 15 Topics Introduction Mathematical Functions Fundamentals of Functional Programming Languages The First Functional Programming Language: Lisp Introduction
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 informationCSc 372. Comparative Programming Languages. 36 : Scheme Conditional Expressions. Department of Computer Science University of Arizona
1/26 CSc 372 Comparative Programming Languages 36 : Scheme Conditional Expressions Department of Computer Science University of Arizona collberg@gmail.com Copyright c 2013 Christian Collberg 2/26 Comparison
More informationCS251 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 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 informationFunctional 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 informationImperative, 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 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 informationChapter 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 informationSD314 Outils pour le Big Data
Institut Supérieur de l Aéronautique et de l Espace SD314 Outils pour le Big Data Functional programming in Python Christophe Garion DISC ISAE Christophe Garion SD314 Outils pour le Big Data 1/ 35 License
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 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 informationCSC324 Functional Programming Efficiency Issues, Parameter Lists
CSC324 Functional Programming Efficiency Issues, Parameter Lists Afsaneh Fazly 1 January 28, 2013 1 Thanks to A.Tafliovich, P.Ragde, S.McIlraith, E.Joanis, S.Stevenson, G.Penn, D.Horton 1 Example: efficiency
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 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 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 informationCS 314 Principles of Programming Languages
CS 314 Principles of Programming Languages Lecture 18: Functional Programming Zheng (Eddy) Zhang Rutgers University April 9, 2018 Review: Defining Scheme Functions (define ( lambda (
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 informationCSc 520 Principles of Programming Languages
CSc 520 Principles of Programming Languages 36 : Scheme Conditional Expressions Christian Collberg Department of Computer Science University of Arizona collberg+520@gmail.com Copyright c 2008 Christian
More informationBox-and-arrow Diagrams
Box-and-arrow Diagrams 1. Draw box-and-arrow diagrams for each of the following statements. What needs to be copied, and what can be referenced with a pointer? (define a ((squid octopus) jelly sandwich))
More informationPrinciples of Programming Languages
Principles of Programming Languages www.cs.bgu.ac.il/~ppl172 Lesson 6 - Defining a Programming Language Bottom Up Collaboration and Management - Elements of Programming Dana Fisman 1 What we accomplished
More informationFunctional Programming in Scala. Raj Sunderraman
Functional Programming in Scala Raj Sunderraman Programming Paradigms imperative programming modifying mutable variables, using assignments, and control structures such as if-then-else, loops, continue,
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 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 informationMIT Scheme Reference Manual
MIT Scheme Reference Manual Edition 1.95 for Scheme Release 7.6.0 26 November 2001 by Chris Hanson the MIT Scheme Team and a cast of thousands Copyright c 1988-2001 Massachusetts Institute of Technology
More informationFunctional Programming Languages (FPL)
Functional Programming Languages (FPL) 1. Definitions... 3 2. Applications... 3 3. Examples... 4 4. FPL Characteristics:... 5 5. Lambda calculus (LC)... 6 5.1. LC expressions forms... 6 5.2. Semantic of
More informationFUNKCIONÁ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 informationFunc%onal Programming in Scheme and Lisp
Func%onal Programming in Scheme and Lisp http://www.lisperati.com/landoflisp/ Overview In a func(onal programming language, func(ons are first class objects You can create them, put them in data structures,
More informationIntroduction to Functional Programming in Haskell 1 / 56
Introduction to Functional Programming in Haskell 1 / 56 Outline Why learn functional programming? The essence of functional programming What is a function? Equational reasoning First-order vs. higher-order
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 informationScheme: 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 informationCIS192: Python Programming
CIS192: Python Programming Introduction Harry Smith University of Pennsylvania January 18, 2017 Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 1 / 34 Outline 1 Logistics Rooms
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 informationRuby: Introduction, Basics
Ruby: Introduction, Basics Computer Science and Engineering College of Engineering The Ohio State University Lecture 4 Ruby vs Java: Similarities Imperative and object-oriented Classes and instances (ie
More informationCS111: PROGRAMMING LANGUAGE II
CS111: PROGRAMMING LANGUAGE II Computer Science Department Lecture 1(c): Java Basics (II) Lecture Contents Java basics (part II) Conditions Loops Methods Conditions & Branching Conditional Statements A
More informationScheme Datatypes. expressions. pairs. atoms. lists. symbols. booleans
Lisp Lisp was invented in 1958 at MIT by John McCarthy. Lisp stands for list processing. Its intended use was research in artificial intelligence. It is based on the λ calculus which was invented by Alonzo
More informationPrinciples of Programming Languages
Ben-Gurion University of the Negev Faculty of Natural Science Department of Computer Science Mira Balaban Lecture Notes April 9, 2013 Many thanks to Tamar Pinhas, Azzam Maraee, Ami Hauptman, Eran Tomer,
More informationFunc%onal Programming in Scheme and Lisp
Func%onal Programming in Scheme and Lisp http://www.lisperati.com/landoflisp/ Overview In a func(onal programming language, func(ons are first class objects You can create them, put them in data structures,
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 informationCIS24 Project #3. Student Name: Chun Chung Cheung Course Section: SA Date: 4/28/2003 Professor: Kopec. Subject: Functional Programming Language (ML)
CIS24 Project #3 Student Name: Chun Chung Cheung Course Section: SA Date: 4/28/2003 Professor: Kopec Subject: Functional Programming Language (ML) 1 Introduction ML Programming Language Functional programming
More informationFunctional Programming and Haskell
Functional Programming and Haskell Tim Dawborn University of Sydney, Australia School of Information Technologies Tim Dawborn Functional Programming and Haskell 1/22 What are Programming Paradigms? A programming
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 informationCS 11 Haskell track: lecture 1
CS 11 Haskell track: lecture 1 This week: Introduction/motivation/pep talk Basics of Haskell Prerequisite Knowledge of basic functional programming e.g. Scheme, Ocaml, Erlang CS 1, CS 4 "permission of
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 informationRACKET BASICS, ORDER OF EVALUATION, RECURSION 1
RACKET BASICS, ORDER OF EVALUATION, RECURSION 1 COMPUTER SCIENCE 61AS 1. What is functional programming? Give an example of a function below: Functional Programming In functional programming, you do not
More informationThe syntax and semantics of Beginning Student
The syntax and semantics of Beginning Student Readings: HtDP, Intermezzo 1 (Section 8). We are covering the ideas of section 8, but not the parts of it dealing with section 6/7 material (which will come
More information