λ Scheme
description
Transcript of λ Scheme
λλSchemeScheme
JD White IIIJD White IIIKevin SweeneyKevin Sweeney
Josh AmickJosh AmickJonathan EitelJonathan Eitel
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
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.
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.
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
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))
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)))))
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
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
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