Add or Sub:What expression do we want to return? We can think about this as a simple if statement,where if our condition is true,we return the result of adding x1 and x2,otherwise,we return false (if cond (+x1x2) (-×1x2) )
Add or Sub: What expression do we want to return? We can think about this as a simple if statement, where if our condition is true, we return the result of adding x1 and x2, otherwise, we return false (if cond (+ x1 x2) (- x1 x2) )
Add or Sub:Let's build the list! We know what our expression should look like,so now let's construct it!We can do this 2 ways: 1)Using list and quoting 2)Using quasiquoting and unquoting
Add or Sub: Let’s build the list! We know what our expression should look like, so now let’s construct it! We can do this 2 ways: 1) Using list and quoting 2) Using quasiquoting and unquoting
Code Writing:Add or Sub Solution (define-macro (add-or-sub cond1 x1 x2) 、(if,cond1 (+,1,2) Using list/quotes: (-,x1,x2)) (list 'if condl (list 'x1 x2) ) (1ist'-x1x2))
Code Writing: Add or Sub (define-macro (add-or-sub cond1 x1 x2) `(if ,cond1 (+ ,x1 ,x2) (- ,x1 ,x2)) ) Using list/quotes: (list 'if cond1 (list '+ x1 x2) (list '- x1 x2)) Solution
Any questions so far?
Any Questions so far? Any questions so far?
Trees OOP Style that is
Trees OOP Style that is