-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathracketskratch.rkt
55 lines (40 loc) · 1.35 KB
/
racketskratch.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
#lang racket
(define objects '(whiskey bucket frog chain))
(define object-locations '(
(whiskey living-room)
(bucket living-room)
(chain garden)
(frog garden)))
#;
(define (doo)
(define (bucket) (cadr objects))
(bucket)
(define (bucket-in-living-room)
(assoc (bucket) object-locations))
(bucket-in-living-room)
(define (at-loc-p-test? obj)
(not (eq? obj 'bucket)))
(at-loc-p-test? "fooo")
(filter at-loc-p-test? objects)
(define (get-location-of-object obj obj-locs)
(cadr (assoc obj obj-locs)))
(get-location-of-object 'bucket object-locations)
)
(define (objects-at loc objs obj-locs)
(define (get-location-of-object current-obj)
(cadr (assoc current-obj obj-locs)))
(define (at-loc-p? obj)
(eq? loc
(get-location-of-object obj)))
(filter (λ (i) (at-loc-p? i)) objs))
;;((λ (a) (eq? a loc)) 'garden))
;;((λ (a b) (eq? a b)) 'a 'b))
;; (filter
;; ((λ (a b) (eq? a 'b)) '(a b c))
;;(filter
;; (λ (arg)
;; (eq? (get-location-of-object arg) loc)) obj-locs))
;;(filter at-loc-p? objs))
;;(get-location-of-object (car objs) obj-locs)
;; (at-loc-p? 'bucket)) ;; is th bucket in the garden?
(objects-at 'living-room objects object-locations)