CS 403: Programming Languages Lecture 6 Fall 2003 Department of Computer Science University of Alabama Joel Jones.

Slides:



Advertisements
Similar presentations
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.
Advertisements

1 Scheme and Functional Programming Aaron Bloomfield CS 415 Fall 2005.
Lists in Lisp and Scheme a. Lists are Lisp’s fundamental data structures, but there are others – Arrays, characters, strings, etc. – Common Lisp has moved.
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.
CSE 341 Lecture 16 More Scheme: lists; helpers; let/let*; higher-order functions; lambdas slides created by Marty Stepp
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.
Lisp – Introduction יעל נצר מערכות נבונות סמסטר ב' תשס"ו.
Introduction to Artificial Intelligence Lisp Ruth Bergman Fall 2002.
Lisp. Versions of LISP Lisp is an old language with many variants –LISP is an acronym for List Processing language Lisp is alive and well today Most modern.
CS 330 Programming Languages 11 / 20 / 2007 Instructor: Michael Eckmann.
6.001 SICP SICP Sections 5 & 6 – Oct 5, 2001 Quote & symbols Equality Quiz.
Chapter 15 Functional Programming Languages. Copyright © 2007 Addison-Wesley. All rights reserved. 1–2 Introduction Design of imperative languages is.
Recursion. Definitions I A recursive definition is a definition in which the thing being defined occurs as part of its own definition Example: A list.
Lisp by Namtap Tapchareon Lisp Background  Lisp was developed by John McCarthy in  Lisp is derives from List Processing Language. 
LISP 1.5 and beyond A very quick tour. Data Atoms (symbols) including numbers – All types of numbers including Roman! (well, in the early days) – Syntactically.
Yu-Tzu Lin ( 林育慈 )
1 Lists in Lisp and Scheme. 2 Lists are Lisp’s fundamental data structures. Lists are Lisp’s fundamental data structures. However, it is not the only.
1 Lisp Functions –Built-in functions –Defining functions –Function Evaluation and Special Forms defun, if Control statements –Conditional if, cond –Repetition.
Functional Programming in Scheme
CSC3315 (Spring 2009)1 CSC 3315 Programming Paradigms Scheme Language Hamid Harroud School of Science and Engineering, Akhawayn University
331 Final Spring Details 6-8 pm next Monday Comprehensive with more emphasis on material since the midterm Study example finals and midterm exams.
Functional Programming in Scheme and Lisp. Overview In a functional programming language, functions are first class objects. You can create them, put.
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 403: Programming Languages Lecture 5 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 18: Think Globally, Mutate Locally.
CS 330 Programming Languages 11 / 13 / 2008 Instructor: Michael Eckmann.
CS 603: Programming Language Organization Lecture 10 Spring 2004 Department of Computer Science University of Alabama Joel Jones.
331 Final Fall Details 3:30-5:30 Friday December 17 th LH4 Comprehensive with more emphasis on material since the midterm Study example finals and.
CS 614: Theory and Construction of Compilers Lecture 7 Fall 2002 Department of Computer Science University of Alabama Joel Jones.
LISP Data Types Functional Programming Academic Year Alessandro Cimatti
CS535 Programming Languages Chapter - 10 Functional Programming With Lists.
Introduction to LISP. Lisp Extensible: It lets you define new operators yourself Lisp programs are expressed as lisp data structures –You can write programs.
UMBC CMSC Common Lisp II. UMBC CMSC Input and Output Print is the most primitive output function > (print (list 'foo 'bar)) (FOO BAR) The.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 19: Environments.
Scheme Profs Tim Sheard and Andrew Black CS 311 Computational Structures.
CS 603: Programming Language Organization Lecture 9 Spring 2003 Department of Computer Science University of Alabama Joel Jones.
CS 614: Theory and Construction of Compilers Lecture 5 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
1 FP Foundations, Scheme In Text: Chapter Chapter 14: FP Foundations, Scheme Mathematical Functions Def: A mathematical function is a mapping of.
CS 603: Programming Language Organization Lecture 1 Spring 2003 Department of Computer Science University of Alabama Joel Jones.
CS 614: Theory and Construction of Compilers Lecture 8 Fall 2002 Department of Computer Science University of Alabama Joel Jones.
Comparative Programming Languages Functional programming with Lisp/Scheme.
Spring 16 CSCI 4430, A Milanova/BG Ryder 1 Announcements HW5 due March 28 Homework Server link is up I will have office hours, Fri or Mon, check Announcements.
CS 152: Programming Language Paradigms February 12 Class Meeting Department of Computer Science San Jose State University Spring 2014 Instructor: Ron Mak.
1 Outline Review Introduction to LISP Symbols and Numbers Lists Writing LISP Functions LISPWorks.
CS 326 Programming Languages, Concepts and Implementation
Lecture 7: List Recursion CS200: Computer Science
CS 326 Programming Languages, Concepts and Implementation
The Environment Model*
September 4, 1997 Programming Languages (CS 550) Lecture 6 Summary Operational Semantics of Scheme using Substitution Jeremy R. Johnson TexPoint fonts.
LISP LISt Processing.
CS 603: Programming Language Organization
Streams Sections 3.5.1,3.5.2 Pages
Lecture #8 מבוא מורחב.
CS 36 – Chapter 11 Functional programming Features Practice
Modern Programming Languages Lecture 20 Fakhar Lodhi
Lecture 14 - Environment Model (cont.) - Mutation - Stacks and Queues
John McCarthy Pioneer in AI Also Lisp Formalize common-sense reasoning
Announcements Quiz 5 HW6 due October 23
List and list operations (continue).
LISP LISt Processing.
LISP LISt Processing.
Common Lisp II.
CS 403: Programming Languages
Lisp.
Defining Macros in Scheme
CS 403: Programming Languages
Lecture 8: Recursing Lists CS150: Computer Science
Presentation transcript:

CS 403: Programming Languages Lecture 6 Fall 2003 Department of Computer Science University of Alabama Joel Jones

Lecture 6©2003 Joel Jones2 Outline Questions Introduction to Scheme Reading for next time

Lecture 6©2003 Joel Jones3 Questions How did the exercises on Squeak go? Any questions on MP1?

Lecture 6©2003 Joel Jones4 What is Functional Programming? Computation using functions Functions are roughly equivalent to those in mathematics Functions are first class objects Define anywhere Pass as arguments—downward fun(ction) arg(ument)s Return as results—upward funargs

Lecture 6©2003 Joel Jones5 Where have we seen this before? Smalltalk blocks are typically used as downward funargs In boolVal ifTrue: [ show a ] the block with show a is an anonymous function passed as an argument to the ifTrue message to boolVal

Lecture 6©2003 Joel Jones6 S-expressions s-expression – a symbol, a number, or a list (S 1, …, S n ) of zero or more S- expressions nil list – list of zero elements () Function application has operator as first element of list and operators following Example: ( ) returns 6

Lecture 6©2003 Joel Jones7 Operations on S-Expressions: car: first element of list or nil cdr: everything in list except first element cons:if S = (S 1,…,S n ), then (cons S’ S) is (S’ S 1,…,S n ) =: returns T if equal, nil otherwise, for non-lists and empty lists number?, symbol?, list?, null?: T if argument of type, nil otherwise +, -, *, / : T if both numbers and condition holds, nil otherwise

Lecture 6©2003 Joel Jones8 Syntax value -> integer | quoted-const value-op -> + | - | * | / | = | | cons | car | cdr |number? | symbol? | list? | null? | print quoted-const -> ‘S-expression S-expression -> integer | symbol | ( S- expression* ) symbol -> name

Lecture 6©2003 Joel Jones9 Let’s Play at the Board Cons cells (cons ‘a ()) (cons ‘a ‘(b)) (cons ‘(a) ‘(b))

Lecture 6©2003 Joel Jones10 Example of a list using function (define length (lambda (l) (if (null? l) 0 (+1 (length (cdr l))))))

Lecture 6©2003 Joel Jones11 Let’s play at the board again (Write the following functions) (list1 x) - list of one element, x (list2 x y) - list of two elements, x and y (list3 x y z) - list of three elements, x, y, and z (atom? x) - T if null, number, or symbol, nil otherwise (equal l1 l2) - T if two equal atoms or equal lists, nil otherwise. Two lists are equal if same length and corresponding elements are equal.

Lecture 6©2003 Joel Jones12 Larger Scheme Example Calculate prime numbers less than n using Sieve of Eratosthenes. (code will be on web site)

Lecture 6©2003 Joel Jones13 Reading & Questions for Next Class Online version of the book “Structure and Interpretation of Computer Programs” at: through and including 1.1.8http://mitpress.mit.edu/sicp/ Note: (define f (lambda (n (+ n 1))) is defined there as (define (f n) (+ n 1)) What data structures can be represented using Scheme-like lists? What data structures can’t be represented using Scheme-like lists?