scheme - In lecture 4a pattern matching what is the colon? -
i started watching lecture 4a sicp, lost. seemed difficulty ramped lecture 3 4. these lectures on youtube out of order current mit course? http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-001-structure-and-interpretation-of-computer-programs-spring-2005/lecture-notes/
https://www.youtube.com/watch?v=amf5ltz0utc&index=7&list=pl8fe88aa54363bc46
can explain me general process he's doing? haven't been reading book, viewing videos on youtube. should stop watching videos , read book , every single exercise along way?
what (: x1) , (? x2) for?
(define deriv-rules '( ( (dd (?c c) (? v)) 0) ( (dd (?v v) (? v)) 1) ( (dd (?v u) (? v)) 0) ; derivative of (+ x1 x2) in respect v ( (dd (+ (? x1) (? x2)) (? v)) (+ (dd (: x1) (: v)) (dd (: x2) (: v)) ) ) ; derivative of (* x1 x2) in respect v ( (dd (* (? x1) (? x2)) (? v)) (+ (* (: x1) (dd (: x2) (: v))) (* (dd (: x1) (: v)) (: x2)) ) ) ; derivative of x^(const) in respect v ( (dd (** (? x) (?c n)) (? v)) (* (* (: n) (** (: x) (: (- n 1)))) (dd (: x) (: v)) ) ) ) )
the colon explained @ 11:37 of video in last link posted. question mark explained bit earlier. let's @ code:
(define deriv-rules '( ( (dd (?c c) (? v)) 0) ; 1 ( (dd (?v v) (? v)) 1) ; 2 ( (dd (?v u) (? v)) 0) ; 3 ; derivative of (+ x1 x2) in respect v ( (dd (+ (? x1) (? x2)) (? v)) ; 4 (+ (dd (: x1) (: v)) (dd (: x2) (: v)) ) ) … deriv-rules a list of lists, each of form (pattern derivative). instance, rules 1, 2, , 3, say, respectively:
- the derivative of constant c respect thing (call v) 0.
- the derivative of variable v respect v 1.
- the derivative of variable u respect (call v) 0.
there's no use of colon in those, because none of derivatives require instantiation. rule 4 says taht derivative of sum x1 + x2 respect v sum of derivative of x1 respect v , derivative of x2 respect v. (: …) notation provides way refer value of variable ….
Comments
Post a Comment