

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Some concept of Building Programming Experience are Trees, Square Limit Language, Special Forms, Quizanssheet, Professor Abstraction, Compound Procedure, Procedures And Recursion. Main points of this lecture are: Procedures And Recursion, Evaluate, Argument Values, Arguments Unspecified, Value, Operator Value, Evaluation, Order, Compound, Procedure
Typology: Slides
1 / 3
This page cannot be seen from the preview
Don't miss anything!


Lecture 2: Procedures and Recursion
Review: Self-evaluating expression #t, 5, “yay” Name expression +, foo, bar
foo | 4
combinations (+ 3 4) to evaluate a combination, sequence of steps: Evaluate operator Evaluate arguments Apply operator value to argument values Order of evaluation of arguments unspecified, but scheme does it right-to-left
Special forms: define (define name value)
(define bar (+ 3 3))
if (if test consequent alternative)
Make mental pictures for better gasp abstract more difficult to hold
Lambda:
((lambda (x) (* x x)) 5) compound procedure in a combination
Lambda procedures are lengthy; in order to reuse over and over again with simplicity, give name.
(define square
All code now must be tabbed accordingly: newly opened paren is where tab should begin. In scheme, simply hit the return key and then hit the tab key, and the correct tab will automatically appear in the code.
Writing Procedures
Not takes one argument, it negates what you see For example: Not true-ish is false Not false is true
(define not (lambda (s) (if s #f #t)))
Evaluation of (not #f):
When you come across a problem Æ break into smaller, more manageable problems
Factorial n! = (n – 1)! * n 0! = 1
(define fact (lambda (n) (if (= n 0) 1 (* n (fact (- n 1))))))
Use substitution model to investigate this If scheme gets stuck in an infinite loop, exit with C-c, C-c.
Defined factorial in terms of itself: this is known as recursion.
Exponentiation x^n = x^(n-1)x X^0 = 1 (define expt (lambda (x n) (if (= n o) 1 ( x (expt x (- n 1))))))