-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsection02.rkt
65 lines (51 loc) · 985 Bytes
/
section02.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#lang racket
(#%provide (all-defined))
;
; ComS342 - Spring 2014
;
; Week 05 Notes
; 4pm Recitation w/ Josh Davis
;
; - Code as data
; - Homework 03
(define (get-function)
'(lambda (x y)
(+ x y)))
(define plus (get-function))
((eval plus) 1 2)
; Will return 1 + 2 = 3
(define (swap-to-minus f)
(cond
((null? f) '())
((list? f)
(cons
(swap-to-minus (car f))
(swap-to-minus (cdr f))))
((eq? f '+)
'-)
(else
f)))
(define minus (swap-to-minus plus))
((eval minus) 1 2)
; Will return 1 - 2 = -1
; More complicated...
(define (get-second-function)
'(lambda (x y z)
(+ 1 2 3
(+ x 3)
(+ 3 y)
(+ x y z)
)
)
)
(define plusplus (get-second-function))
; Swap again...
(define minusminusminus (swap-to-minus plusplus))
((eval plusplus) 7 8 9)
; Will return 51
((eval minusminusminus) 7 8 9)
; Will return 7
;
; Homework 3...
; Just went over the README and discussed the problems.
;