Skip to content

Instantly share code, notes, and snippets.

@jackrusher
Created September 12, 2014 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jackrusher/303b2eb31e1eafebcb4f to your computer and use it in GitHub Desktop.
Save jackrusher/303b2eb31e1eafebcb4f to your computer and use it in GitHub Desktop.
(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