




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





# 1
# 2
/* This is a variation of RGB RMS error. The final square-root has been eliminated to / / speed up the process. We can do this because we only care about relative error. / / /* HSV RMSfinding error orsource images that are visually similar to the portion of other matching systems could be used here, as long as the targetthe goal image / of / / under consideration is met. / for(i = 0; i > size; i++) { rt = (int) ((unsigned char)rmas[i] - (unsigned char)image->r[i]); gt = (int) ((unsigned char)gmas[i] - (unsigned char) image->g[i]; bt = (int) ((unsigned char)bmas[i] - (unsigned char)image->b[i]; result += (rtrt+gtgt+btbt); }* Your code should never look like this! Use new lines and indenting to make it easy to understand the structure of your code! (Note: unless you are writing a patent. Then the goal is to make it as hard to understand as possible.)
# 7
Lists are pretty important – hard to write a useful Scheme program without them. # 9
# 10
# 19
Scheme provides primitive implementations for cons, car, and cdr. But, we could define them ourselves. **Advanced Detail!
# 21
(define ( triple a b c) (cons a (cons b c))) (define ( t-first t) (car t)) (define ( t-second t) (car (cdr t))) (define ( t-third t) (cdr (cdr t))) # 22
A quadruple is a pair where the second part is a triple (define ( quadruple a b c d) (cons a (triple b c d))) (define ( q-first q) (car q)) (define ( q-second q) (t-first (cdr t))) (define ( q-third t) (t-second (cdr t))) (define ( q-fourth t) (t-third (cdr t)))
A list is a pair where the second part is a list. One big problem: how do we stop? This only allows infinitely long lists!
# 25
List ::= (cons Element List ) List ::= A list is either: a pair where the second part is a list or, empty The function list? returns #t for a list and #f for all other values. It’s hard to write this! # 26
List ::= (cons Element List ) List ::= A list is either: a pair where the second part is a list or, empty ( null ) The function null? returns #t for the empty list and #f for all other values.
# 27
> null () > (cons 1 null) (1) > (list? null) #t > (list? (cons 1 2)) #f > (list? (cons 1 null)) **#t Why #f?
Try these on paper!
# 37
(define (my-procedure my-input) (if ( is-base-case? my-input) ( handle-base-case my-input) ( combine ( first-part-of my-input) (my-procedure (rest-of my-input)))))
(define (my-procedure my-input) (if ( is-base-case? my-input) ( handle-base-case my-input) ( combine ( first-part-of my-input) (my-procedure (rest-of my-input)))))
# 43
(define (my-procedure my-input) (if ( is-base-case? my-input) ( handle-base-case my-input) ( combine ( first-part-of my-input) (my-procedure (rest-of my-input)))))