Additional Scheme examples

Slides:



Advertisements
Similar presentations
Joshua Eckroth The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the.
Advertisements

Lisp II. How EQUAL could be defined (defun equal (x y) ; this is how equal could be defined (cond ((numberp x) (= x y)) ((atom x) (eq x y)) ((atom y)
Functional Programming. Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends.
Lisp II. How EQUAL could be defined (defun equal (x y) ; this is how equal could be defined (cond ((numberp x) (= x y)) ((atom x) (eq x y)) ((atom y)
CSE 341 Lecture 16 More Scheme: lists; helpers; let/let*; higher-order functions; lambdas slides created by Marty Stepp
CSI2520  Un arbre binaire peut être représentée avec des listes imbriquées a / \ b c / \ d e (a b (c d e)) ou (a (b () ()) (c (d () ()) (e () ())) ou.
מבוא מורחב 1 Lecture #7. מבוא מורחב 2 The rational number abstraction Wishful thinking: (make-rat ) Creates a rational number (numer ) Returns the numerator.
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.
Prolog: Lists Recall lists in Scheme: '(a b c) = (cons 'a (cons 'b (cons c '()))) ls = (cons (car ls) (cdr ls)) Want the same operations in Prolog: [a,
מבוא מורחב למדעי המחשב בשפת Scheme בוחן אמצע אביב 2006 פתרון לדוגמא.
6.001 SICP SICP – October Trees Trevor Darrell 32-D512 Office Hour: W web page:
מבוא מורחב למדעי המחשב בשפת Scheme תרגול 7 1. Outline More list examples Symbols 2.
6.001 SICP SICP – October HOPs, Lists, Trees Trevor Darrell 32-D512 Office Hour: W web page:
מבוא מורחב למדעי המחשב בשפת Scheme תרגול 11. Dotted tail notation (define (proc m1 m2. opt) ) Mandatory Arguments: m1, m2 Mandatory Arguments: m1, m2.
6.001 SICP SICP Sections 5 & 6 – Oct 5, 2001 Quote & symbols Equality Quiz.
6.001 SICP SICP – October Introduction Trevor Darrell 32-D512 Office Hour: W web page:
Scheme examples. Recursion Iteration is achieved via recursion Selection is achieved via COND Review the following examples to learn to think recursively.
Functional programming: LISP Originally developed for symbolic computing First interactive, interpreted language Dynamic typing: values have types, variables.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 25: Trees and Generalized Lists.
PPL Pairs, lists and data abstraction. Data Abstraction? An interface: separate implementation from usage Think of the Map interface in Java: we know.
Spring 2008Programming Development Techniques 1 Topic 6 Hierarchical Data and the Closure Property Section September 2008.
CS 152: Programming Language Paradigms February 24 Class Meeting Department of Computer Science San Jose State University Spring 2014 Instructor: Ron Mak.
CSC3315 (Spring 2009)1 CSC 3315 Programming Paradigms Scheme Language Hamid Harroud School of Science and Engineering, Akhawayn University
The Evolution of Programming Languages Day 2 Lecturer: Xiao Jia The Evolution of PLs1.
Plt /12/ Data Abstraction Programming Language Essentials 2nd edition Chapter 2.3 Representation Strategies for Data Types.
Functional Programming and Lisp. Overview In a functional programming language, functions are first class objects. In a functional programming language,
Practice session #6: 1. Sequence operations 2. Partial evaluation with currying 3. Lazy-lists.
Information Retrieval: aka “Google-lite” CMSC November 27, 2006.
COP4020 Programming Languages Functional Programming Prof. Xin Yuan.
Introduction to Scheme. Lisp and Scheme Lisp: List processor language –Full recursion –Conditional expression –Extensibility –Interactive Scheme: one.
18-October-2002cse Symbols © 2002 University of Washington1 Symbols CSE 413, Autumn 2002 Programming Languages
Abstraction: Procedures as Parameters CMSC Introduction to Computer Programming October 14, 2002.
COP4020 Programming Languages Functional Programming Prof. Xin Yuan.
Spring 2004Programming Development Techniques 1 Topic 11 Sets and their Representation April 2004.
Practice session 5 טיפוסים מורכבים Abstract Data Types הכנה לעבודה 3.
The “Beauty” of Scheme: Programs as Proofs Q: Is '(abc 123) a list? A: Yes Proof:  '(abc 123) = (cons 'abc (cons 123 '()))  '() is a list, so (cons 123.
Scope: What’s in a Name? CMSC Introduction to Computer Programming October 16, 2002.
Functional Programming: Lisp MacLennan Chapter 10.
מבוא מורחב למדעי המחשב בשפת Scheme תרגול 8. Outline 1.The special form quote 2.Data abstraction: Trie 3.Alternative list: Triplets 4.Accumulate-n.
CS61A Lecture Colleen Lewis. Clicker poll Where do you think you’re learning the most? I assume you’ll learn the most in lab & disc (so.
CS61A Lecture Colleen Lewis. Clicker poll Do you feel comfortable posting questions to piazza? A)Yes with my classmates and instructors.
Cs784 (Prasad)L6AST1 Abstract Syntax. cs784 (Prasad)L6AST2 Language of -expressions ::= | (lambda ( ) ) | ( ) E.g., concrete syntax Scheme S-expressions.
CS314 – Section 5 Recitation 10
CS 550 Programming Languages Jeremy Johnson
Pairs and Lists. Data Abstraction. SICP: Sections – 2.2.1
6.001 SICP Object Oriented Programming
Racket CSC270 Pepper major portions credited to
The Environment Model*
CS 270 Math Foundations of CS Jeremy Johnson
COP4020 Programming Languages
Carine Iskander Pia Chakrabarti
Streams Sections 3.5.1,3.5.2 Pages
Lecture 18 Infinite Streams and
FP Foundations, Scheme In Text: Chapter 14.
Programming Languages (CS 550) Mini Language Semantics
Lisp Tutorial Click on Xlisp icon – you enter the interpreter
Lecture 18.
Lecture #8 מבוא מורחב.
Lecture 16: Tables and OOP
Modern Programming Languages Lecture 20 Fakhar Lodhi
Lecture 26: The Metacircular Evaluator Eval Apply
Mutators for compound data Stack Queue
Lecture #7 מבוא מורחב.
List and list operations (continue).
Functional Programming: Lisp
List Allocation and Garbage Collection
Lecture # , , , , מבוא מורחב.
To understand recursion, one must first understand recursion.
More Scheme CS 331.
Lecture 25: The Metacircular Evaluator Eval Apply
Presentation transcript:

Additional Scheme examples (define f (lambda (x) (lambda (y) (lambda (z) (+ x y z) ) ) ) ) > f #<CLOSURE (x) #@lambda (lambda (y) (lambda (z) (+ x y z)))> > (f 1) #<CLOSURE (y) #@lambda (lambda (z) (+ x y z))> > ((f 1) 2) #<CLOSURE (z) #@lambda (+ x y z)> > (((f 1) 2) 3) 6

Additional Scheme examples ( map car '((a b) (c d) (e f)) ) ( map cadr '((a b) (c d) (e f)) ) ( map (lambda (x) (cons 0 (list x))) '(a b c d) )

Additional Scheme examples (define (repeatedElems L) (if (list? L) (doRepeatedElems L) 'repeated_elems_not_a_list) ) (define (doRepeatedElems L) (cond ((null? L) ()) ((member (car L) (cdr L)) (cons (car L) (doRepeatedElems (deleteAll (car L) (cdr L))) ) ) (else (doRepeatedElems (cdr L)))

Additional Scheme examples (define (deleteAll L Ls) (cond ((null? Ls) ()) ((equal? (car Ls) L) (deleteAll L (cdr Ls))) (else (cons (car Ls) (deleteAll L (cdr Ls)))) ) ) > (repeatedElems '(a b c a d e a f g e w c a i))