CS 135- Final Exam Guide - Comprehensive Notes for the exam ( 144 pages long!)

484 views144 pages

Document Summary

I(cid:374)ter(cid:373)ediate la(cid:374)guage pro(cid:448)ides the special for(cid:373) (cid:862)local(cid:863: contains a series of local definitions plus an expression using them, (cid:894)local [(cid:894)defi(cid:374)e (cid:454)(cid:1005) e(cid:454)p(cid:1005)(cid:895) (cid:894)defi(cid:374)e (cid:454)(cid:374) e(cid:454)p(cid:374)(cid:895)] (cid:271)odye(cid:454)p(cid:895) Co(cid:374)sider hero(cid:374)"s for(cid:373)ula for the area of a tria(cid:374)gle. +c)/2 (define (t-area a b c) (sqrt ( (/ (+ a b c) 2) (cid:894)/ (cid:894)+ (cid:894) a(cid:895) (cid:271) c(cid:895) (cid:1006)(cid:895) (cid:894)/ (cid:894)+ a (cid:894) (cid:271)(cid:895) c(cid:895) (cid:1006)(cid:895) (cid:894)/ (cid:894)+ a (cid:271) (cid:894) c(cid:895)(cid:895) (cid:1006)(cid:895)(cid:895)(cid:895)(cid:895) This does (cid:374)ot (cid:373)ake the relatio(cid:374)ship to hero(cid:374)"s for(cid:373)ula is u(cid:374)clear, a(cid:374)d the technique does not generalize. The relationship between this code and hero(cid:374)"s for(cid:373)ula is u(cid:374)clear, a(cid:374)d the tech(cid:374)i(cid:395)ue does (cid:374)ot generalize. Able to generalize, but still hard to see relationship. The local special form we introduced provides a natural way to bring the definition and use together. (define (t-area4 a b c) (local. [(define s (/ (+ a b c) 2))] (sqrt ( s ( s a) ( s b) ( s c)))))