CS 326 Programming Languages, Concepts and Implementation

Slides:



Advertisements
Similar presentations
CS 63 LISP Philip Greenspun's Tenth* Rule of Programming:
Advertisements

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.
1 Scheme and Functional Programming Aaron Bloomfield CS 415 Fall 2005.
Scheme in Scheme. Why implement Scheme in Scheme  Implementing a language is a good way to learn more about programming languages  Interpreters are.
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.
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 Programming. LISP – simple and powerful mid-1950’s by John McCarthy at M.I.T. “ LIS t P rocessing language” Artificial Intelligence programs LISP.
1 Functional programming Languages And a brief introduction to Lisp and Scheme.
Introduction to Artificial Intelligence Lisp Ruth Bergman Fall 2002.
Functional programming: LISP Originally developed for symbolic computing Main motivation: include recursion (see McCarthy biographical excerpt on web site).
The Scheme Programming Language History and Significance Dmitry Nesvizhsky CIS24 Professor Danny Kopec.
CMSC 471 LISP. Why Lisp? Because it’s the most widely used AI programming language Because it’s good for writing production software (Graham article)
Common Lisp Derek Debruin Mark Larue Vinh Doan. Problem Domains There was a need in the early 1960s to define a programming language whose computational.
Functional programming: LISP Originally developed for symbolic computing First interactive, interpreted language Dynamic typing: values have types, variables.
TES3111 October 2001 Artificial Intelligence LISP.
Lisp and Scheme I. Versions of LISP LISP is an acronym for LISt Processing language Lisp is an old language with many variants – Fortran is the only older.
1 (Functional (Programming (in (Scheme)))) Jianguo Lu.
Functional Programing Referencing material from Programming Language Pragmatics – Third Edition – by Michael L. Scott Andy Balaam (Youtube.com/user/ajbalaam)
Functional Programming in Scheme
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 7.
CS 152: Programming Language Paradigms February 17 Class Meeting Department of Computer Science San Jose State University Spring 2014 Instructor: Ron Mak.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 5.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 8.
CS 330 Programming Languages 11 / 13 / 2008 Instructor: Michael Eckmann.
COP4020 Programming Languages Functional Programming Prof. Xin Yuan.
CS535 Programming Languages Chapter - 10 Functional Programming With Lists.
Scheme Profs Tim Sheard and Andrew Black CS 311 Computational Structures.
Milos Hauskrecht (PDF) Hieu D. Vu (PPT) LISP PROGARMMING LANGUAGE.
Introduction to LISP Atoms, Lists Math. LISP n LISt Processing n Function model –Program = function definition –Give arguments –Returns values n Mathematical.
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.
LISP LISt Processing. History & Overview b b One of the oldest high level programming languages. b b First developed in 1958 by John McCarthy. b b Later.
CS314 – Section 5 Recitation 9
Functional Programming
Functional Programming Languages
Functional Programming
CS 3304 Comparative Languages
CS 326 Programming Languages, Concepts and Implementation
CS 326 Programming Languages, Concepts and Implementation
CS 326 Programming Languages, Concepts and Implementation
CS 326 Programming Languages, Concepts and Implementation
Scheme : variant of LISP
September 4, 1997 Programming Languages (CS 550) Lecture 6 Summary Operational Semantics of Scheme using Substitution Jeremy R. Johnson TexPoint fonts.
LISP LISt Processing.
CSE S. Tanimoto Introduction
The Metacircular Evaluator
FP Foundations, Scheme In Text: Chapter 14.
CS 36 – Chapter 11 Functional programming Features Practice
CSE S. Tanimoto Introduction
The Metacircular Evaluator (Continued)
Streams, Delayed Evaluation and a Normal Order Interpreter
Lisp and Scheme I.
Lisp, Then and Now.
CSE S. Tanimoto Introduction
6.001 SICP Variations on a Scheme
CSE 3302 Programming Languages
Defining Functions with DEFUN
LISP LISt Processing.
Abstraction and Repetition
6.001 SICP Interpretation Parts of an interpreter
LISP LISt Processing.
COP4020 Programming Languages
Modern Programming Languages Lecture 18 Fakhar Lodhi
topics interpreters meta-linguistic abstraction eval and apply
Rehearsal: Lazy Evaluation Infinite Streams in our lazy evaluator
Lisp.
Presentation transcript:

CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 5 Good afternoon and thank you everyone for coming. My talk today will describe the research I performed at the IRIS at USC, the object of this work being to build a computational framework that addresses the problem of motion analysis and interpretation.

The Scheme Programming Language 1950s-1960s: Lisp developed at MIT (John McCarthy), based on lambda calculus (Alonzo Church) Lisp - the first functional programming language No single standard evolved for Lisp Two major Lisp dialects - Common Lisp and Scheme Scheme - developed at MIT in 1970s Member of functional class of programming languages Actually - has a functional core plus some imperative features Main application - symbolic computing, artificial intelligence

The Structure of a Scheme Program All programs and data are expressions Expressions can be atoms or lists Atom: number, string, identifier, character, boolean List: sequence of expressions separated by spaces, between parentheses Syntax: expression  atom | list atom  number | string | identifier | character | boolean list  ( expr_seq ) expr_seq  expression expr_seq | expression

Interacting with Scheme Interpretor: "read-eval-print" loop > 1 1 Reads 1, evaluates it (1 evaluates to itself), then prints its value > (+ 2 3) 5 + => function + 2 => 2 3 => 3 Applies function + on operands 2 and 3 => 5

Evaluation Constant atoms - evaluate to themselves 42 - a number 3.14 - another number "hello" - a string #/a - character 'a' #t - boolean value "true" > "hello world" "hello world"

Evaluation Identifiers (symbols) - evaluate to the value bound to them (define a 7) > a 7 > + #<procedure +>

Evaluation Lists - evaluate as "function calls": (function arg1 arg2 arg3 ...) First element must evaluate to a function Recursively evaluate each argument Apply the function on the evaluated arguments > (- 7 1) 6 > (* (+ 2 3) (/ 6 2)) 15

Operators - More Examples Prefix notation Any number of arguments > (+) > (+ 2) 2 > (+ 2 3) 5 > (+ 2 3 4) 9 > (- 10 7 2) 1 > (/ 20 5 2) 2

Preventing Evaluation (quote) Evaluate the following: > (1 2 3) Error: attempt to apply non-procedure 1. Use the quote to prevent evaluation: > (quote (1 2 3)) (1 2 3) Short-hand notation for quote: > '(1 2 3)

Error: attempt to apply non-procedure 5. More Examples (define a 7) a => 7 'a => a (+ 2 3) => 5 '(+ 2 3) => ((+ 2 3)) => (+ 2 3) Error: attempt to apply non-procedure 5. '(her 3 "sons") => (her 3 "sons") Make a list: (list 'her (+ 2 1) "sons") => (her 3 "sons") (list '(+ 2 1) (+ 2 1)) => ((+ 2 1) 3)

Forcing Evaluation (eval) (+ 1 2 3) => 6 '(+ 1 2 3) => (+ 1 2 3) (eval '(+ 1 2 3)) => 6 (list + 1 2) => (+ 1 2) (eval (list + 1 2)) => 3 Eval evaluates its single argument Eval is implicitly called by the interpretor to evaluate each expression entered: “read-eval-print” loop

Special Forms Have different rules regarding whether/how arguments are evaluated (define a 5) ; binds a to 5, does not evaluate a 5 a (quote (1 2 3)) ; does not evaluate (1 2 3) There are a few other special forms – discussed later

Using Scheme Petite Chez Scheme The essentials: free downloads for Windows, Linux, Unix The essentials: scheme ; to start Scheme from the Unix prompt ^C ; to interrupt a running Scheme program (exit) ; to exit Scheme Documentation available on Chez Scheme webpage

List Operations cons – returns a list built from head and tail (cons 'a '(b c d)) => (a b c d) (cons 'a '()) => (a) (cons '(a b) '(c d)) => (cons 'a (cons 'b '())) => ((a b) c d) (a b) (cons 'a 'b) => (a . b) ; improper list

List Operations car – returns first member of a list (head) (car '(a b c d)) => a (car '(a)) => a (car '((a b) c d)) => (car '(this (is no) more difficult)) => this cdr – returns the list without its first member (tail) (cdr '(a b c d)) => (b c d) (cdr '(a b)) => (b) (cdr '(a)) => () (cdr '(a (b c))) => (car (cdr (cdr '(a b c d)))) => c (caddr '(a b c d)) => c (a b) ((b c))

Announcements Readings May look at Scheme books or on-line references