Presentation is loading. Please wait.

Presentation is loading. Please wait.

Structure & Interpretation of Computer Programs Xiao Ben Charrow.

Similar presentations


Presentation on theme: "Structure & Interpretation of Computer Programs Xiao Ben Charrow."— Presentation transcript:

1 Structure & Interpretation of Computer Programs Xiao Ben Charrow

2 电脑程序的结构和编译 萧潇 陈斌

3 Who We Are Xiao Xiao MIT, Junior, Majoring in Computer Science x_x@mit.edu Ben Charrow MIT, Senior, Majoring in Computer Science bcharrow@mit.edu

4 What We Want to Cover The "Scheme" programming language Data Abstraction / 数据抽象 Iterative and recursive processes / 重复和递归进程 Data structures / 数据结构 Basic algorithms / 算法

5 Our Bible / 我们的圣经 电脑程序的 结构和编译 SICP (sick-pea) Wizard Book / 巫师书

6 Scheme Language features Simple (syntax / 语法 & specification / 规格 ) Prefix notation / 前缀表示法 Interpreted / 解释器 Tail-recursive / 尾递归 Weakly typed / 弱类型 Functional

7 Simplicity The Scheme specification is 50 pages long The Java specification is 684 pages long Scheme is designed to be as simple and small as possible

8 Interpreters / 解释器 Characteristics Each line of code is only examined at runtime / 运行时间 Works on all computer architectures / 计算机体系结构 Easy to fix problems Slower than compiled / 编译器 code

9 Scheme Keywords Keywords: Words that have a 'special meaning' to the scheme interpreter They are what allow you to make programs

10 Prefix Notation / 前缀表示法 The function ( 函数 ) always comes before its arguments (+ 3 4) (- 5 3) (* 5 4) 7 2 20

11 Keyword Example: define (define x y) Makes the value of x the value of y Does not work if y does not have a value (define x 3) x 3

12 Combining Ideas (define x 12) (define x 5) (define y x) (* x y) 25 15 (+ x 3)

13 Defining Procedures Want to define a function that squares its argument Call the function 'square' Call the argument 'arg' How do we write it in scheme?

14 Defining Procedures (cont.) (define (square arg) (* arg arg)) (square 4) 16

15 Weakly Typed Unlike C++ and Java, scheme does not worry about types! Don't need to declare variables as 'int' or 'char' Makes generalizing code easier Be careful what you pass! (define (add arg1 arg2) (+ arg1 arg2)) (add 'a 'b)

16 Another Keyword: cond cond Similar to the 'if' statement in C++ or Java If predicate is #t / true, then it evaluates the statement If predicate is #f / false, then it moves on (define (sign? arg) (cond ((> 0 arg) ’negative) ((< 0 arg) ’positive) (else 'zero)))

17 Recursion (next lecture) A 'recursive procedure' calls itself Factorial(n) = n! If n > 0, Factorial(n) = n*Factorial(n-1) otherwise factorial(n) = 1 Factorial is a recursive procedure


Download ppt "Structure & Interpretation of Computer Programs Xiao Ben Charrow."

Similar presentations


Ads by Google