Scheme for Python Programmers CSE 399 005 Valeria Montero.

Slides:



Advertisements
Similar presentations
C-LISP. LISP 2 Lisp was invented by John McCarthy in 1958 while he was at the Massachusetts Institute of Technology (MIT).John McCarthyMassachusetts Institute.
Advertisements

1 Scheme and Functional Programming Aaron Bloomfield CS 415 Fall 2005.
CSE 3341/655; Part 4 55 A functional program: Collection of functions A function just computes and returns a value No side-effects In fact: No program.
1 Programming Languages (CS 550) Lecture Summary Functional Programming and Operational Semantics for Scheme Jeremy R. Johnson.
Functional Programming. Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends.
1 Programming Languages and Paradigms Lisp Programming.
Lambda Calculus and Lisp PZ03J. Lambda Calculus The lambda calculus is a model for functional programming like Turing machines are models for imperative.
Chapter 3 Functional Programming. Outline Introduction to functional programming Scheme: an untyped functional programming language.
CS 355 – PROGRAMMING LANGUAGES Dr. X. Apply-to-all A functional form that takes a single function as a parameter and yields a list of values obtained.
1-1 An Introduction to Scheme March Introduction A mid-1970s dialect of LISP, designed to be a cleaner, more modern, and simpler version than.
CSE 3302 Programming Languages Chengkai Li Fall 2007 Functional Programming Language (Introduction and Scheme) Lecture 17 – Functional Programming, Spring.
Cs7100(Prasad)L11Clos1 Closures and Streams. Contemporary Interest in Closures The concept of closures was developed in the 1960s and was first fully.
Introduction to Artificial Intelligence Lisp Ruth Bergman Fall 2002.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 14 Functional Programming It is better to.
Chapter 15 Functional Programming Languages. Copyright © 2007 Addison-Wesley. All rights reserved. 1–2 Introduction Design of imperative languages is.
Symbolic Expressions (S Expressions) Syntax: Opening and Closing parenthesis having elements in between. List represented in LISP: (A B2 C3 Shahid) (A.
Functional programming: LISP Originally developed for symbolic computing First interactive, interpreted language Dynamic typing: values have types, variables.
SchemeCOP Introduction to Scheme. SchemeCOP Scheme Meta-language for coding interpreters –“ clean ” semantics Scheme = LISP + ALGOL –simple.
(5.1) COEN Functional Languages  Functional programming basics  Atoms and lists; cons  Useful primitive functions  Predicates  Arithmetic functions.
1 (Functional (Programming (in (Scheme)))) Jianguo Lu.
SCHEME By: Krista and Brett. What is Scheme? Best known for its functional style of programming One of two main dialects of Lisp Developed in 1975 –MIT.
CS 152: Programming Language Paradigms February 24 Class Meeting Department of Computer Science San Jose State University Spring 2014 Instructor: Ron Mak.
Slide 1 Vitaly Shmatikov CS 345 Introduction to Scheme.
Functional Programming in Scheme
CSC3315 (Spring 2009)1 CSC 3315 Programming Paradigms Scheme Language Hamid Harroud School of Science and Engineering, Akhawayn University
ISBN Chapter 15 Functional Programming Languages.
Functional Programming in Scheme and Lisp. Overview In a functional programming language, functions are first class objects. You can create them, put.
Λ => Scheme for Rubyists. Scheme History Authors: Guy Steele and Gerald Sussman Structure and Interpretation of Computer Programs (SICP) by Abelson &
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 7.
Functional Programming and Lisp. Overview In a functional programming language, functions are first class objects. In a functional programming language,
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 8.
SCHEME Scheme is elegant, clear, small, and powerful programming language. It is a dialect of LISP and can be classified as a semi-functional programming.
Introduction to Scheme. Lisp and Scheme Lisp: List processor language –Full recursion –Conditional expression –Extensibility –Interactive Scheme: one.
Lisp Functional Language or Applicative Language –Achieves its effect by applying functions, either recursively or through composition Powerful, expressive,
ISBN Chapter 15 Functional Programming Languages.
ISBN Chapter 15 Functional Programming Languages.
Functional Programming CS331 Chapter 14. Functional Programming Original functional language is LISP –LISt Processing –The list is the fundamental data.
Scheme Profs Tim Sheard and Andrew Black CS 311 Computational Structures.
Milos Hauskrecht (PDF) Hieu D. Vu (PPT) LISP PROGARMMING LANGUAGE.
Functional Programming: Lisp MacLennan Chapter 10.
1 FP Foundations, Scheme In Text: Chapter Chapter 14: FP Foundations, Scheme Mathematical Functions Def: A mathematical function is a mapping of.
Functional Programming. Some Functional Languages Lisp Scheme - a dialect of Lisp Haskell Miranda.
CSE 425: Functional Programming I Programs as Functions Some programs act like mathematical functions –Associate a set of input values from the function’s.
Ada, Scheme, R Emory Wingard. Ada History Department of Defense in search of high level language around Requirements drafted for the language.
C H A P T E R E I G H T Functional Programming Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
CS 152: Programming Language Paradigms February 12 Class Meeting Department of Computer Science San Jose State University Spring 2014 Instructor: Ron Mak.
Ch Ch jcmt CSE 3302 Programming Languages CSE3302 Programming Languages (n-n-n-notes) Summer 2003 Dr. Carter Tiernan.
Functional Languages  A function is an “association of a certain object from one set (the range) with each object from another set (the domain)  A function.
CS314 – Section 5 Recitation 9
Functional Programming
CS314 – Section 5 Recitation 10
Functional Programming Languages
Additional Scheme examples
Functional Programming Languages
Functional Programming
History of Computing – Lisp
Section 15.4, 15.6 plus other materials
CS 550 Programming Languages Jeremy Johnson
CS 326 Programming Languages, Concepts and Implementation
6.001 SICP Object Oriented Programming
COP4020 Programming Languages
FP Foundations, Scheme In Text: Chapter 14.
Functional Programming Languages
The Metacircular Evaluator
CS 36 – Chapter 11 Functional programming Features Practice
Bindings, Scope, and Extent
Lisp and Scheme I.
Functional Programming: Lisp
Common Lisp II.
More Scheme CS 331.
Presentation transcript:

Scheme for Python Programmers CSE Valeria Montero

Scheme  LISP origins  AI (MIT): High level features reprogram Slower  Teaching  Scheme and Python: Lambda, deep lexicals

Scheme vs. Python  Synthax: Prefix vs. main-stream  Lexical Scope: Parentheses vs. Whitespace  Control Structures: Functional (tail-recursion-optimizing) vs... mainstream (while, for loops)  Support: Standard (R5RS, IEEE) vs. not  OOP: indirect support vs. Standard object system  Orientation: Mathematical vs. Processor

Scheme vs. Python  Implementation: Many vs. 2 synchronized. (Portable)  Garbage collection: Strong (cycles) vs. weak  Built in: No standard library vs. many data types, functions. (regular expressions, internet connectivity)  Macros vs. not  Scheme great for scripting/extension

Getting Started Define ;Create new objects: Global Variable or Function (define ) Operators ( …) Common Operators: and, or, not, -, +, *, %, /

Scheme Python Pre-Operator Order ( #t(+ 3 5) => 8(and #t #f) => #f (Blocks)

Quick Sort

Conditional (cond ( ) ( ) ( )) Absolute Value: (define (abs x) (cond ((< x 0) (- x)) (x))) Python: If Elif Else

CAR and CDR (car list) => first element (car '(a b c)) => a (cdr list) => list excluding car (cdr '(a b c)) => (b c)

Play Around with Nested Lists: Reference maximum four car/cdr (cadar '((1 2 3) 3)) => 2 (cadr '(1 2 3)) => 2 (cadar '((1 2 3) 4 5 6))=> 2 (cddddr '( ))=>(5 6)

APPEND and CONS Append: Concatenates two lists Cons: Constructs list with input: car, cdr > (append '(1 2) '(3 4)) ( ) > (cons '(1 2) '(3 4)) ((1 2) 3 4)

Let Variables are bounded locally within Let body. (let ((variable 1 value 1 )...) expression 1 expression 2...) (let ((a (* 4 4))) (+ a a)) => 32 (let ((+ *)) (+ 2 3)) => 6 Absolute Value: (define (abs n) (let ((a n) (b (-n))) (max a b)))

Let vs. Let* Let evaluates the variables in parallel. Let* evaluates the variables sequentially. (let ((a 5) (b (* a 10))) b) => reference to undefined identifier: a (let* ((a 5) (b (* a 10))) b) => 50 Python Parallel assignments a, b = b, a

Scheme Functional Programming: Lambda Calculus COND Absolute Value: (define (abs x) (cond ((< x 0) (- x)) (x))) LET Absolute Value: (define (abs n) (let ((a n) (b (-n))) (max a b))) Lambda (λ) ((lambda (variable 1...) expression 1 expression 2...) value 1...) λ Absolute Value: (define abs (λ (n) (if (>= n 0) n (- n))))

List Recursion Style Style Style …

Permutations

For Comparison

Do: Iterative vs. Recursive (do ((variable 1 value 1 ) (variable 2 value 2 ) …) ((exitCondition) (exitFunction)) Body)

Fun Debugging in DrScheme (car '()) > car: expects argument of type ; given () UESTIONS?