-
Notifications
You must be signed in to change notification settings - Fork 1
/
Exercise 3.25 make-table generalized.rkt
745 lines (649 loc) · 20.3 KB
/
Exercise 3.25 make-table generalized.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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
#lang racket
; Exercise 3.25. Generalizing one- and two-dimensional tables, show how to implement a table in which
; values are stored under an arbitrary number of keys and different values may be stored under different
; numbers of keys. The lookup and insert! procedures should take as input a list of keys used to access
; the table.
; S O L U T I O N
(require rnrs/mutable-pairs-6)
(require compatibility/mlist)
; Supported table structure is something like:
; TABLE
; -----
; K1: val1
; K2: val2
; K3: val3
; K31: val31
; K32: (no value)
; K321: val321
; K322: val322
; K33: val33
; K4: val4
;
; So the key combinations to retrieve data would be:
;
; K1 retrieves val1
; K2 retrieves val2
; K3 retrieves val3
; K3, K31 retrieves val31
; K3, K32, K321 retrieves val321
; K3, K32, K322 retrieves val322
; K3, K33 retrieves val33
; K4 retrieves val4
; Note: I want to allow for the possibility for not just primitives like string literals and numbers
; but objects to be inserted and looked up from the table. Since every non-primitive object is
; implemented using pairs, this makes it necessary for us to be able to distinguish between a sub-table
; and a value which is an object. So I am introducing tags so that the table procedures can correctly
; identify the data they handle as they traverse through the table. So a 'key' will not be just a
; string literal but a pair in which the 'car' is a tag with the value 'key and the 'cdr' is the actual key
; Similarly, a 'value' will not just be a string literal but a pair in which the 'car' is a tag with the
; value 'value and the 'cdr' is the actual value which could be a primitive or a complex object
(define (make-table same-key?)
(define (make-generic-table)
; Make an empty table structure
(mlist '*generic-table*)
)
(let ((local-table (make-generic-table)))
(define (get-records table)
(if (mpair? table)
(mcdr table)
null
)
)
(define (get-first-key-value-pair records)
(if (mpair? records)
(mcar records)
null
)
)
(define (get-remaining-key-value-pairs records)
(if (mpair? records)
(mcdr records)
null
)
)
(define (insert-at-top-level! table key-value-pair)
(set-mcdr! table (mcons key-value-pair (get-records table)))
)
(define (find-key same-key-proc key-to-find records)
(cond
((null? records) false)
; check if the first key-value pair matches
((same-key-proc key-to-find (get-key (get-first-key-value-pair records)))
(get-first-key-value-pair records)
)
(else
; continue looking at this level in the table
(find-key same-key-proc key-to-find (get-remaining-key-value-pairs records))
)
)
)
(define (lookup same-key-proc list-of-keys)
(define (lookup-internal key-list table)
(cond
((null? key-list) false)
((not (pair? key-list)) false)
(else
(let ((key-value-pair (find-key same-key-proc (car key-list) (get-records table))))
(if key-value-pair
; Found key
; If this is the last key in the list of keys, then we have found the
; data we are looking for in the table.
(if (null? (cdr key-list))
; we have reached the last key, so return the value if there is one
(if (not (null? (get-value key-value-pair)))
(get-value key-value-pair)
false
)
; we have to look for more keys
(lookup-internal (cdr key-list) (get-subtable key-value-pair))
)
; Could not find key, so stop looking and return false
false
)
)
)
)
)
(lookup-internal list-of-keys local-table)
)
(define (insert! key-list value)
; Logic: Look for the first key from the key-list in the first level of the table
; If found, then look for the 2nd key in the sub-table pointed to by the first key
; and continue this process. If all the keys are found, then the insert operation will
; replace the existing value with the new value.
; If at any level the key is not found, then insert that key at that level in the table and
; continue inserting keys below it and finally the value
(define (insert-internal! list-of-keys value table)
(let ((key-value-pair (find-key same-key? (car list-of-keys) (get-records table))))
(if key-value-pair
; found the key
; if this is the last key in the list of keys, then we have found the
; correct location in the table. So replace the old value with the new value
(if (null? (cdr list-of-keys))
; we are at the last key, so replace the old value with the new value
(set-value! key-value-pair (make-value value))
; there are more keys so continue
(begin
; If there is no subtable inside this key-value pair, create it
(if (null? (get-subtable key-value-pair))
(set-subtable! key-value-pair (make-generic-table))
(void)
)
(insert-internal! (cdr list-of-keys) value (get-subtable key-value-pair))
)
)
; did not find the key so we need to insert key(s) and the value TODO
(insert-new-keys-and-value list-of-keys value table)
)
)
)
; This procedure is for inserting a new set of hierarchical keys in the supplied
; set of records
(define (insert-new-keys-and-value list-of-keys value table)
(cond
((not (pair? list-of-keys)) (error "Not a list" list-of-keys))
; if this is the last key then we insert the value also and stop
((null? (cdr list-of-keys))
(let ((new-key-value-pair (make-key-value-pair (car list-of-keys) null value)))
(insert-at-top-level! table new-key-value-pair)
)
)
(else
; the tricky part
(let ((new-key-value-pair (make-key-value-pair (car list-of-keys) null null)))
(let ((subtable (make-generic-table)))
(insert-new-keys-and-value (cdr list-of-keys) value subtable)
(set-subtable! new-key-value-pair subtable)
)
(insert-at-top-level! table new-key-value-pair)
)
)
)
)
(if (pair? key-list)
(begin
(insert-internal! key-list value local-table)
'ok
)
(error "Supplied parameter is not a pair! -- INSERT!" key-list)
)
)
(define (print-table)
(define (print-table-internal records indentation-level)
(cond
((null? records) (void))
((not (mpair? records)) (display "Supplied records not a pair -- PRINT-TABLE"))
(else
(let ((first-record (mcar records)) (remaining-records (mcdr records)))
(indent indentation-level)
(print-key-and-value first-record)
(print-table-internal (get-records (get-subtable first-record)) (+ indentation-level 1))
(print-table-internal remaining-records indentation-level)
)
)
)
)
(define (indent indentation-level)
(if (= indentation-level 0)
(void)
(begin
(display " ")
(indent (- indentation-level 1))
)
)
)
(define (print-key-and-value key-value-pair)
(display (get-key key-value-pair))
(display ": ")
(if (not (null? (get-value key-value-pair)))
(display (get-value key-value-pair))
(void)
)
(newline)
)
(display "GENERIC-TABLE")
(newline)
(display "-------------")
(newline)
(print-table-internal (get-records local-table) 0)
)
(define (make-key-value-pair key subtable value)
; A key-value pair is the basic building block of the table. It is a pair in which
; the 'car' is the key and the 'cdr' is another pair in which the 'car' is a pointer to
; a generic table and the 'cdr' is the value. This structure allows us to create an
; arbitrary number of levels in the table. If it is just a simple key-value pair with no
; sub-keys, then the contained generic table will be null. If it is a key with sub-keys
; but no value for this key, then the contained generic table will be non-null and the
; value will be null. And of course, both the contained generic table and the value
; can be non-null to allow for data like:
; K3, K31: val31
; K3, K32, K321: val321
(mcons (make-key key) (mcons subtable (make-value value)))
)
(define (get-key key-value-pair)
(if (mpair? key-value-pair)
(mcdr (mcar key-value-pair))
null
)
)
(define (get-value key-value-pair)
(mcdr (mcdr (mcdr key-value-pair)))
)
(define (get-subtable key-value-pair)
(mcar (mcdr key-value-pair))
)
(define (set-subtable! key-value-pair subtable)
(set-mcar! (mcdr key-value-pair) subtable)
)
(define (set-value! key-value-pair x)
(set-mcdr! (mcdr key-value-pair) x)
)
(define (make-key key) (mcons 'key key))
(define (make-value value) (mcons 'value value))
(define (dispatch m)
(cond
((eq? m 'lookup-proc) lookup)
((eq? m 'insert-proc!) insert!)
((eq? m 'print) print-table)
(else (error "Unknown operation -- TABLE" m))
)
)
dispatch
)
)
; Test Driver
(define (run-test return-type proc . args)
(define (print-item-list items first-time?)
(cond
((not (pair? items)) (void))
(else
(if (not first-time?)
(display ", ")
(void)
)
(print (car items))
(print-item-list (cdr items) false)
)
)
)
(display "Applying ")
(display proc)
(if (not (null? args))
(begin
(display " on: ")
(print-item-list args true)
)
(void)
)
(newline)
(let ((result (apply proc args)))
(if (not (eq? return-type 'none))
(display "Result: ")
(void)
)
(cond
((procedure? result) ((result 'print)))
; ((eq? return-type 'deque) (print-deque result))
((eq? return-type 'none) (void))
(else
(print result)
(newline)
)
)
)
(newline)
)
(define (execution-time proc . args)
(define start-time (current-milliseconds))
; (display start-time)
; (display " ")
(apply proc args)
(define end-time (current-milliseconds))
; (display end-time)
(display "Execution time of ")
(display proc)
(display ": ")
(- end-time start-time)
)
(define (same? a b)
(equal? a b)
)
; Tests
(define T1 (make-table same?))
(run-test 'unknown (T1 'insert-proc!) (list 'Afghanistan) 'AF)
(run-test 'none (T1 'print))
(run-test 'unknown (T1 'insert-proc!) (list 'Kazhakhistan) 'KZ)
(run-test 'none (T1 'print))
(run-test 'unknown (T1 'insert-proc!) (list 'Turkmenistan) 'TM)
(run-test 'none (T1 'print))
(run-test 'unknown (T1 'insert-proc!) (list 'Kyrgiztan) 'KZ)
(run-test 'none (T1 'print))
(run-test 'unknown (T1 'insert-proc!) (list 'India 'Karnataka) 'KA)
(run-test 'none (T1 'print))
(run-test 'unknown (T1 'insert-proc!) (list 'India) 'IN)
(run-test 'none (T1 'print))
(run-test 'unknown (T1 'insert-proc!) (list 'India 'TamilNadu) 'TU)
(run-test 'none (T1 'print))
(run-test 'unknown (T1 'insert-proc!) (list 'Pakistan) 'PK)
(run-test 'none (T1 'print))
(run-test 'unknown (T1 'insert-proc!) (list 'Pakistan 'Sindh) 'SD)
(run-test 'none (T1 'print))
(run-test 'unknown (T1 'insert-proc!) (list 'Pakistan 'Sindh) 'SN)
(run-test 'none (T1 'print))
(run-test 'unknown (T1 'insert-proc!) (list 'India 'TamilNadu) 'TN)
(run-test 'none (T1 'print))
(run-test 'unknown (T1 'insert-proc!) (list 'India 'TamilNadu 'Chennai) 'CHEN)
(run-test 'none (T1 'print))
(run-test 'unknown (T1 'insert-proc!) (list 'Pakistan 'Sindh 'Rawalpindi) 'RAWA)
(run-test 'none (T1 'print))
(run-test 'unknown (T1 'insert-proc!) (list 'India 'TamilNadu 'Chennai 'BesantNagar 'ElliotsBeach) 'ELLIOTS)
(run-test 'none (T1 'print))
(run-test 'unknown (T1 'insert-proc!) (list 'India) 'BH)
(run-test 'none (T1 'print))
(run-test 'unknown (T1 'insert-proc!) (list 'Pakistan) 'PoK)
(run-test 'none (T1 'print))
(run-test 'unknown (T1 'insert-proc!) (list 'Uzbekistan) 'UB)
(run-test 'none (T1 'print))
(run-test 'unknown (T1 'insert-proc!) (list 'Tajikistan) 'TJ)
(run-test 'none (T1 'print))
(display "Testing the lookup proc")
(newline)
(run-test 'unknown (T1 'lookup-proc) same? (list 'Tajikistan))
(run-test 'unknown (T1 'lookup-proc) same? (list 'Uzbekistan))
(run-test 'unknown (T1 'lookup-proc) same? (list 'Burma))
(run-test 'unknown (T1 'lookup-proc) same? (list 'Pakistan))
(run-test 'unknown (T1 'lookup-proc) same? (list 'Sindh))
(run-test 'unknown (T1 'lookup-proc) same? (list 'Pakistan 'Sindh))
(run-test 'unknown (T1 'lookup-proc) same? (list 'Pakistan 'Sindh 'Rawalpindi))
(run-test 'unknown (T1 'lookup-proc) same? (list 'Pakistan 'Sind 'Rawalpindi))
(run-test 'unknown (T1 'lookup-proc) same? (list 'India))
(run-test 'unknown (T1 'lookup-proc) same? (list 'TamilNadu))
(run-test 'unknown (T1 'lookup-proc) same? (list 'India 'TamilNadu))
(run-test 'unknown (T1 'lookup-proc) same? (list 'India 'TamilNadu 'Chennai))
(run-test 'unknown (T1 'lookup-proc) same? (list 'India 'TamilNadu 'Chennai 'BesantNagar))
(run-test 'unknown (T1 'lookup-proc) same? (list 'India 'TamilNadu 'Chennai 'BesantNagar 'ElliotsBeach))
(run-test 'unknown (T1 'lookup-proc) same? (list 'Karnataka))
(run-test 'unknown (T1 'lookup-proc) same? (list 'Karnataka 'India))
(run-test 'unknown (T1 'lookup-proc) same? (list 'India 'Karnataka))
(run-test 'unknown (T1 'lookup-proc) same? (list 'Kyrgiztan))
(run-test 'unknown (T1 'lookup-proc) same? (list 'Turkmenistan))
(run-test 'unknown (T1 'lookup-proc) same? (list 'Kazhakhstan))
(run-test 'unknown (T1 'lookup-proc) same? (list 'Kazakhstan))
(run-test 'unknown (T1 'lookup-proc) same? (list 'Kazhakhistan))
(run-test 'unknown (T1 'lookup-proc) same? (list 'Afghanistan))
; Test Results
Welcome to DrRacket, version 6.11 [3m].
Language: racket, with debugging; memory limit: 512 MB.
Applying #<procedure:insert!> on: '(Afghanistan), 'AF
Result: 'ok
Applying #<procedure:print-table>
GENERIC-TABLE
-------------
Afghanistan: AF
Applying #<procedure:insert!> on: '(Kazhakhistan), 'KZ
Result: 'ok
Applying #<procedure:print-table>
GENERIC-TABLE
-------------
Kazhakhistan: KZ
Afghanistan: AF
Applying #<procedure:insert!> on: '(Turkmenistan), 'TM
Result: 'ok
Applying #<procedure:print-table>
GENERIC-TABLE
-------------
Turkmenistan: TM
Kazhakhistan: KZ
Afghanistan: AF
Applying #<procedure:insert!> on: '(Kyrgiztan), 'KZ
Result: 'ok
Applying #<procedure:print-table>
GENERIC-TABLE
-------------
Kyrgiztan: KZ
Turkmenistan: TM
Kazhakhistan: KZ
Afghanistan: AF
Applying #<procedure:insert!> on: '(India Karnataka), 'KA
Result: 'ok
Applying #<procedure:print-table>
GENERIC-TABLE
-------------
India:
Karnataka: KA
Kyrgiztan: KZ
Turkmenistan: TM
Kazhakhistan: KZ
Afghanistan: AF
Applying #<procedure:insert!> on: '(India), 'IN
Result: 'ok
Applying #<procedure:print-table>
GENERIC-TABLE
-------------
India: IN
Karnataka: KA
Kyrgiztan: KZ
Turkmenistan: TM
Kazhakhistan: KZ
Afghanistan: AF
Applying #<procedure:insert!> on: '(India TamilNadu), 'TU
Result: 'ok
Applying #<procedure:print-table>
GENERIC-TABLE
-------------
India: IN
TamilNadu: TU
Karnataka: KA
Kyrgiztan: KZ
Turkmenistan: TM
Kazhakhistan: KZ
Afghanistan: AF
Applying #<procedure:insert!> on: '(Pakistan), 'PK
Result: 'ok
Applying #<procedure:print-table>
GENERIC-TABLE
-------------
Pakistan: PK
India: IN
TamilNadu: TU
Karnataka: KA
Kyrgiztan: KZ
Turkmenistan: TM
Kazhakhistan: KZ
Afghanistan: AF
Applying #<procedure:insert!> on: '(Pakistan Sindh), 'SD
Result: 'ok
Applying #<procedure:print-table>
GENERIC-TABLE
-------------
Pakistan: PK
Sindh: SD
India: IN
TamilNadu: TU
Karnataka: KA
Kyrgiztan: KZ
Turkmenistan: TM
Kazhakhistan: KZ
Afghanistan: AF
Applying #<procedure:insert!> on: '(Pakistan Sindh), 'SN
Result: 'ok
Applying #<procedure:print-table>
GENERIC-TABLE
-------------
Pakistan: PK
Sindh: SN
India: IN
TamilNadu: TU
Karnataka: KA
Kyrgiztan: KZ
Turkmenistan: TM
Kazhakhistan: KZ
Afghanistan: AF
Applying #<procedure:insert!> on: '(India TamilNadu), 'TN
Result: 'ok
Applying #<procedure:print-table>
GENERIC-TABLE
-------------
Pakistan: PK
Sindh: SN
India: IN
TamilNadu: TN
Karnataka: KA
Kyrgiztan: KZ
Turkmenistan: TM
Kazhakhistan: KZ
Afghanistan: AF
Applying #<procedure:insert!> on: '(India TamilNadu Chennai), 'CHEN
Result: 'ok
Applying #<procedure:print-table>
GENERIC-TABLE
-------------
Pakistan: PK
Sindh: SN
India: IN
TamilNadu: TN
Chennai: CHEN
Karnataka: KA
Kyrgiztan: KZ
Turkmenistan: TM
Kazhakhistan: KZ
Afghanistan: AF
Applying #<procedure:insert!> on: '(Pakistan Sindh Rawalpindi), 'RAWA
Result: 'ok
Applying #<procedure:print-table>
GENERIC-TABLE
-------------
Pakistan: PK
Sindh: SN
Rawalpindi: RAWA
India: IN
TamilNadu: TN
Chennai: CHEN
Karnataka: KA
Kyrgiztan: KZ
Turkmenistan: TM
Kazhakhistan: KZ
Afghanistan: AF
Applying #<procedure:insert!> on: '(India TamilNadu Chennai BesantNagar ElliotsBeach), 'ELLIOTS
Result: 'ok
Applying #<procedure:print-table>
GENERIC-TABLE
-------------
Pakistan: PK
Sindh: SN
Rawalpindi: RAWA
India: IN
TamilNadu: TN
Chennai: CHEN
BesantNagar:
ElliotsBeach: ELLIOTS
Karnataka: KA
Kyrgiztan: KZ
Turkmenistan: TM
Kazhakhistan: KZ
Afghanistan: AF
Applying #<procedure:insert!> on: '(Pakistan), 'PoK
Result: 'ok
Applying #<procedure:print-table>
GENERIC-TABLE
-------------
Pakistan: PoK
Sindh: SN
Rawalpindi: RAWA
India: IN
TamilNadu: TN
Chennai: CHEN
BesantNagar:
ElliotsBeach: ELLIOTS
Karnataka: KA
Kyrgiztan: KZ
Turkmenistan: TM
Kazhakhistan: KZ
Afghanistan: AF
Applying #<procedure:insert!> on: '(Uzbekistan), 'UB
Result: 'ok
Applying #<procedure:print-table>
GENERIC-TABLE
-------------
Uzbekistan: UB
Pakistan: PoK
Sindh: SN
Rawalpindi: RAWA
India: IN
TamilNadu: TN
Chennai: CHEN
BesantNagar:
ElliotsBeach: ELLIOTS
Karnataka: KA
Kyrgiztan: KZ
Turkmenistan: TM
Kazhakhistan: KZ
Afghanistan: AF
Applying #<procedure:insert!> on: '(Tajikistan), 'TJ
Result: 'ok
Applying #<procedure:print-table>
GENERIC-TABLE
-------------
Tajikistan: TJ
Uzbekistan: UB
Pakistan: PoK
Sindh: SN
Rawalpindi: RAWA
India: IN
TamilNadu: TN
Chennai: CHEN
BesantNagar:
ElliotsBeach: ELLIOTS
Karnataka: KA
Kyrgiztan: KZ
Turkmenistan: TM
Kazhakhistan: KZ
Afghanistan: AF
Testing the lookup proc
Applying #<procedure:lookup> on: #<procedure:same?>, '(Tajikistan)
Result: 'TJ
Applying #<procedure:lookup> on: #<procedure:same?>, '(Uzbekistan)
Result: 'UB
Applying #<procedure:lookup> on: #<procedure:same?>, '(Burma)
Result: #f
Applying #<procedure:lookup> on: #<procedure:same?>, '(Pakistan)
Result: 'PoK
Applying #<procedure:lookup> on: #<procedure:same?>, '(Sindh)
Result: #f
Applying #<procedure:lookup> on: #<procedure:same?>, '(Pakistan Sindh)
Result: 'SN
Applying #<procedure:lookup> on: #<procedure:same?>, '(Pakistan Sindh Rawalpindi)
Result: 'RAWA
Applying #<procedure:lookup> on: #<procedure:same?>, '(Pakistan Sind Rawalpindi)
Result: #f
Applying #<procedure:lookup> on: #<procedure:same?>, '(India)
Result: 'IN
Applying #<procedure:lookup> on: #<procedure:same?>, '(TamilNadu)
Result: #f
Applying #<procedure:lookup> on: #<procedure:same?>, '(India TamilNadu)
Result: 'TN
Applying #<procedure:lookup> on: #<procedure:same?>, '(India TamilNadu Chennai)
Result: 'CHEN
Applying #<procedure:lookup> on: #<procedure:same?>, '(India TamilNadu Chennai BesantNagar)
Result: #f
Applying #<procedure:lookup> on: #<procedure:same?>, '(India TamilNadu Chennai BesantNagar ElliotsBeach)
Result: 'ELLIOTS
Applying #<procedure:lookup> on: #<procedure:same?>, '(Karnataka)
Result: #f
Applying #<procedure:lookup> on: #<procedure:same?>, '(Karnataka India)
Result: #f
Applying #<procedure:lookup> on: #<procedure:same?>, '(India Karnataka)
Result: 'KA
Applying #<procedure:lookup> on: #<procedure:same?>, '(Kyrgiztan)
Result: 'KZ
Applying #<procedure:lookup> on: #<procedure:same?>, '(Turkmenistan)
Result: 'TM
Applying #<procedure:lookup> on: #<procedure:same?>, '(Kazhakhstan)
Result: #f
Applying #<procedure:lookup> on: #<procedure:same?>, '(Kazakhstan)
Result: #f
Applying #<procedure:lookup> on: #<procedure:same?>, '(Kazhakhistan)
Result: 'KZ
Applying #<procedure:lookup> on: #<procedure:same?>, '(Afghanistan)
Result: 'AF
>