Created
September 12, 2014 20:10
-
-
Save jackrusher/303b2eb31e1eafebcb4f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (update-in ht ks v) | |
(cond [(empty? (cdr ks)) (hash-set ht (car ks) v)] | |
[else (hash-set ht (car ks) (update-in (hash-ref ht (car ks)) (cdr ks) v))])) | |
(define test-hash (hash 'fruit (hash 'apple 'red 'banana 'green) | |
'veg (hash 'aubergine 'purple))) | |
(update-in test-hash '(fruit banana) 'yellow) | |
;; => #hash((fruit . #hash((apple . red) (banana . yellow))) (veg . #hash((aubergine . purple)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment