Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE S. Tanimoto Introduction

Similar presentations


Presentation on theme: "CSE S. Tanimoto Introduction"— Presentation transcript:

1 CSE 341 -- S. Tanimoto Introduction
Scheme Scheme is a dialect of Lisp. 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* * in How to Become a Hacker, quoted by Paul Graham (see the CSE 341 Syllabus page) CSE S. Tanimoto Introduction

2 Lisp and Scheme Implementations
LISP = LISt Processing (Intended for processing symbolic information) Lisp implementations from noncommercial sites: GNU Common Lisp (GCL) - U of Texas mods to Kyoto Common Lisp CLISP -- developed in Germany. Lisp implementations from Allegro Common Lisp for Windows, Web edition. Allegro Common Lisp for Linux DrScheme: MzScheme with a GUI. (free) Cadence Research: Chez Scheme (commercial version) Petite Chez Scheme (free interp. w/out compiler) CSE S. Tanimoto Introduction

3 Scheme: Our Objectives
Motivation and History Interactive programming Functional programming List manipulation with recursive functions Polymorphism Language extensibility via macro definitions Closures (compare with objects) Scheme on the Web CSE S. Tanimoto Introduction

4 History of Lisp and Scheme
John McCarthy, developed the ideas during the Dartmouth Summer Research Project on Artificial Intelligence, 1956. First implementation on the IBM 704 John McCarthy published “Recursive functions of symbolic expressions and their computation by machine” in Communications of the Association for Computing Machinery in 1960. CSE S. Tanimoto Introduction

5 History of Lisp & Scheme (continued)
1970s: advanced dialects -- MacLisp, InterLisp; Lisp machines (Symbolics, Inc.; Lisp Machines, Inc.; Xerox; Texas Instruments) 1975: Scheme. Late 1970s: Portable Standard Lisp, XLISP. 1984. Common Lisp. Use of Lisp as internal scripting languages: Gnu Emacs, AutoCAD. 1987 CLOS = Common Lisp Object System. 1991 IEEE Standard approved for Scheme. 1991 Revised4 Report for Scheme. 1994 ANSI Standard Lisp. 1990s - Scheme as scripting lang. in the GIMP. CSE S. Tanimoto Introduction

6 Interacting with Scheme
Interaction takes place in a Listener Window. Scheme runs an endless “READ-EVAL-PRINT loop” for interacting with the user: READ EVAL PRINT CSE S. Tanimoto Introduction

7 Interacting with Scheme (continued)
> (+ 3 5) 8 > (* 2.5 (+ 2 2)) 10.0 > (define x 5) > (sqrt x) > (* x x) 25 CSE S. Tanimoto Introduction

8 CSE 341 -- S. Tanimoto Introduction
Scheme’s Syntax Scheme uses one fundamental syntactic construct, the “symbolic expression” or S-expression. Any “atom” such as a number or a symbol, is an S-expression. Any parenthesized list of S-expressions, separated by whitespace, is an S-expression. A procedural form is a list of the form (procedure-name arg1 arg2 ... argN) This is sometimes called parenthesized prefix form. (+ 3 5) (* 2.5 ( )) (sqrt x) CSE S. Tanimoto Introduction

9 CSE 341 -- S. Tanimoto Introduction
Parentheses in Scheme Every parenthesis in an S-expression has significance. (a b c) is different from (a (b c)) or ((a b) c). To call a zero-argument function, put its name in parentheses: (read) But not ((read)) The empty list is denoted ( ). Parentheses should always be balanced. (+ 3 (* 4 5) is an incomplete S-expression. Misplaced paren’s are a leading cause of beginners’ Scheme programming errors. CSE S. Tanimoto Introduction

10 CSE 341 -- S. Tanimoto Introduction
In-Class Exercise Convert the following mathematical expressions into Scheme’s parenthesized prefix form. a b x + 9 y + z c w / 7 mod 255 d P and Q or R e y = f(x + 1) CSE S. Tanimoto Introduction

11 CSE 341 -- S. Tanimoto Introduction
Defining a function > (* 5 5 5) 125 > (define (cube n) (* n n n)) > (cube 2) 8 > (cube ) CSE S. Tanimoto Introduction

12 CSE 341 -- S. Tanimoto Introduction
Symbolic Values Symbols are like identifiers, but they are commonly used as values as well as variables. > (define x ’pizza) > x PIZZA > (define pizza ’pepperoni) > pizza PEPPERONI > (eval x) CSE S. Tanimoto Introduction

13 More on Evaluation of Symbols
> (define x ’y) > (define y ’z) > (define z ’x) > x Y > (eval x) Z > (eval (eval x)) X CSE S. Tanimoto Introduction

14 CSE 341 -- S. Tanimoto Introduction
Values of Symbols A symbol without a value in the current context is said to be “unbound”. The value of a symbol can be any Scheme object, including a number, another symbol, a procedure, a list, and array, etc. A symbol can have several local (“lexical”) values and one global value. However, symbols belong to “packages”, and two different packages can have symbols with the same name. CSE S. Tanimoto Introduction


Download ppt "CSE S. Tanimoto Introduction"

Similar presentations


Ads by Google