-
Notifications
You must be signed in to change notification settings - Fork 0
/
associative-data.lisp
118 lines (77 loc) · 1.76 KB
/
associative-data.lisp
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
(list :chris 34 :dave 38 :nicky 34 :alex 43)
;; => (:CHRIS 34 :DAVE 38 :NICKY 34 :ALEX 43)
(getf (list :a 1 :b 2) :a)
;; => 1
(append (list :x 1 :y 2) (list :bob 3 :alice 4))
;; => (:X 1 :Y 2 :BOB 3 :ALICE 4)
(append (list :a 6 :b 5) (list :b 4))
;; => (:A 6 :B 5 :B 4)
(getf (append (list :a 6 :b 5) (list :b 4)) :b)
;; => 5
;;; A-List (associative list)
(list (cons :a 1) (cons :b 2))
;; => ((:A . 1) (:B . 2))
(assoc :sally (list (cons :bob 5) (cons :sally 7)))
;; => (:SALLY . 7)
(cdr (assoc :sally (list (cons :bob 5) (cons :sally 7))))
;; => 7
(assoc :dave (list (cons :bob 5) (cons :sally 7)))
;; => NIL
(assoc :dave (list (cons :dave 1) (cons :dave 2) (cons :dave 3)))
;; => (:DAVE . 1)
(acons :dave 1 ())
;; => ((:DAVE . 1))
(append (list (cons :butts "nice")) ())
;; => ((:BUTTS . "nice"))
(cons (cons :butts "nice") nil)
;; => ((:BUTTS . "nice"))
(rassoc 2 (list (cons :butts 2)))
;; => (:BUTTS . 2)
(rassoc "nice" (list (cons :butts "nice")))
;; => NIL
(rassoc "nice" (list (cons :butts "nice")) :test #'equal)
;; => ((:BUTTS . "nice")
(defparameter *a-table* (make-hash-table))
;; => *A-TABLE*
(gethash :dave *a-table*)
;; => NIL
;; NIL
(setf (gethash :dave *a-table*) 45)
;; => 45
(gethash :dave *a-table*)
;; => 45
;; T
(gethash :bobine *a-table* 4)
;; => 4
;; NIL
(remhash :dave *a-table*)
;; => NIL
(gethash :dave *a-table*)
;; => NIL
;; NIL
;; => NIL
(gethash :dave *a-table*)
;; => NIL
;; NIL
;; => NIL
(gethash :dave *a-table*)
;; => NIL
;; NIL
;; => NIL
(gethash :dave *a-table*)
;; => NIL
;; NIL
;; => NIL
(gethash :dave *a-table*)
;; => NIL
;; NIL
;; => NIL
(gethash :dave *a-table*)
;; => NIL
;; NIL
(remhash :blah *a-table*)
;; => NIL
(setf (gethash :dave *a-table*) 45)
;; => 45
(remhash :dave *a-table*)
;; => T