SICP Study Session 1
Elements of Programming
What is Computer Science?
Procedures Vs Processes
Procedure
Process
Elements in Programming
Procedures
Data
“The language also serves as a framework within which we organize our ideas about processes.”
Three mechanisms to organize ideas
What are expressions?
Anything (or a construct) that returns a value upon evaluation.
Combinations
(+ 100 200)
300
{
Operator
Operands
The value of a combination is obtained by applying the procedure specified by the operator to the arguments that are the values of the operands.
Creating Abstractions
(define pi 3.14)
variable
value
Define is the simplest means of abstraction is Scheme (a dialect of LISP). It is a variable-binding construct.
How LISP interpreter evaluates an expression?
To evaluate a combination, do the following:
1. Evaluate the subexpressions of the combination.
2. Apply the procedure that is the value of the leftmost subexpression (the operator) to the arguments that are the values of the other subexpressions (the operands).
How is the interpreter going to evaluate this?
Tree Accumulation
Defining a procedure
Compound Procedure
The Substitution Model for Procedure Application
Applicative Order
(default)
Normal Order
Types of Evaluation
(define (square x) (* x x))
(define (sum-of-squares x y)
(+ (square x) (square y)))
(define (f a)
(sum-of-squares (+ a 1) (* a 2)))
(define (p) (p))
(define (test x y)
(if (= x 0)
0
y))
(test 0 (p))
Thank You