λ Scheme

10
λ λ Scheme Scheme JD White III JD White III Kevin Sweeney Kevin Sweeney Josh Amick Josh Amick Jonathan Eitel Jonathan Eitel

description

λ Scheme. JD White III Kevin Sweeney Josh Amick Jonathan Eitel. About. Scheme was invented by Guy Lewis Steele Jr. and Gerald Jay Sussman in the 1970’s Dialect of Lisp Designed for clear and simple semantics One of the first languages to incorporate first class procedures - PowerPoint PPT Presentation

Transcript of λ Scheme

Page 1: λ Scheme

λλSchemeScheme

JD White IIIJD White IIIKevin SweeneyKevin Sweeney

Josh AmickJosh AmickJonathan EitelJonathan Eitel

Page 2: λ Scheme

AboutAbout

Scheme was invented by Guy Lewis Scheme was invented by Guy Lewis Steele Jr. and Gerald Jay Sussman in the Steele Jr. and Gerald Jay Sussman in the 1970’s1970’sDialect of Lisp Dialect of Lisp Designed for clear and simple semantics Designed for clear and simple semantics One of the first languages to incorporate One of the first languages to incorporate first class proceduresfirst class proceduresIntroduced concept of exact and inexact Introduced concept of exact and inexact numbersnumbers

Page 3: λ Scheme

About (cont.)About (cont.)

Supports multiple programming paradigmsSupports multiple programming paradigms

Best known for support of functional Best known for support of functional programmingprogramming

Follows a minimalist philosophy; Follows a minimalist philosophy; everything provided by librarieseverything provided by libraries

Widely used by schools for introductory Widely used by schools for introductory programming courses: Stanford, MIT, etc.programming courses: Stanford, MIT, etc.

Page 4: λ Scheme

ConceptsConcepts

Scheme has lexical scoping and uniform Scheme has lexical scoping and uniform evaluation rulesevaluation rules

All data types are equalAll data types are equal

There are seven kinds of expressions: There are seven kinds of expressions: Constant, Variable reference, Procedure Constant, Variable reference, Procedure creation, Procedure application, creation, Procedure application, Conditional, Assignment, and Sequence. Conditional, Assignment, and Sequence.

Page 5: λ Scheme

TypesTypes

NumbersNumbers 1, 2, 3.1459, 1, 2, 3.1459,

StringsStrings ““Take home exam, please”Take home exam, please”

Char’sChar’s #\a, #\b#\a, #\b

BoolsBools #t #f#t #f

Page 6: λ Scheme

SyntaxSyntax

Compute expressions from the inside outCompute expressions from the inside out

No operator precedence rulesNo operator precedence rules

Uses fully nested and parenthesized notationUses fully nested and parenthesized notation

Conditionals:Conditionals: ((ifif test then-expr else-expr) test then-expr else-expr)

Nested Conditionals:Nested Conditionals: ((condcond (test1 expr1 ...) (test2 expr2 ...) ... ( (test1 expr1 ...) (test2 expr2 ...) ... (elseelse

exprn)) exprn))

Page 7: λ Scheme

Sample Program: FactorialSample Program: Factorial

(define (fact n) (define (fact n)

(if (< n 2) (if (< n 2)

11

(* n (fact (- n (* n (fact (- n 1)))))) 1))))))

(defun fact (n) (defun fact (n)

(if (< n 2) (if (< n 2)

1 1

(* n (fact (1- n)))))(* n (fact (1- n)))))

Page 8: λ Scheme

Prefix vs. InfixPrefix vs. Infix

Prefix: (* 2 (+ 1 2))Prefix: (* 2 (+ 1 2)) Parenthesis are a mustParenthesis are a must (+ 2 4 6 8) = 20(+ 2 4 6 8) = 20

Infix: 2 * ( 1 + 2)Infix: 2 * ( 1 + 2) Parenthesis used to override execution orderParenthesis used to override execution order If the more than 2 arguments, then the If the more than 2 arguments, then the

operator must be repeatedoperator must be repeated

These have the same execution orderThese have the same execution order

Page 9: λ Scheme

Scheme vs. CScheme vs. C

SchemeScheme

(factorial 3)(factorial 3)

(+ 1 2)(+ 1 2)

(+ 1 2 3)(+ 1 2 3)

(< low X high)(< low X high)

( * (+ 1 2) 3)( * (+ 1 2) 3)

CC

Factorial(9)Factorial(9)

1+21+2

1+2+31+2+3

(low < X) && (hi < X)(low < X) && (hi < X)

(1 + 2) * 3(1 + 2) * 3

Page 10: λ Scheme

SourcesSources

Wikipedia: Wikipedia: http://en.wikipedia.org/wiki/Scheme_programming_languagehttp://en.wikipedia.org/wiki/Scheme_programming_language

MIT: http://www-swiss.ai.mit.edu/projects/scheme/MIT: http://www-swiss.ai.mit.edu/projects/scheme/

University of Washington: University of Washington: http://www.cs.washington.edu/education/courses/341/99su/lectures/http://www.cs.washington.edu/education/courses/341/99su/lectures/scheme/ppframe.htmscheme/ppframe.htm

University of Michigan-Dearborn: University of Michigan-Dearborn: http://www.engin.umd.umich.edu/CIS/course.des/cis400/scheme/schttp://www.engin.umd.umich.edu/CIS/course.des/cis400/scheme/scheme.htmlheme.html