Skip to content

Instantly share code, notes, and snippets.

@gengar
Last active October 29, 2015 06:56
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 gengar/82787aabb4fc0b27228e to your computer and use it in GitHub Desktop.
Save gengar/82787aabb4fc0b27228e to your computer and use it in GitHub Desktop.
(define ~/default
(case-lambda
((obj index default)
(ref obj index default))
((obj index i x . xs)
(apply ~/default
(ref obj index)
i x xs))))
(define-syntax ~~
(syntax-rules ()
((_ args ...)
(letrec ((recur
(case-lambda
((obj index args ...)
(ref obj index args ...))
((obj index args ... x . xs)
(apply recur
(ref obj index)
args ... x
xs)))))
recur))))
;; gosh> (define ht (make-hash-table))
;; ht
;; gosh> ((~~ default) ht 'foo 'bar)
;; bar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment