Skip to content

Instantly share code, notes, and snippets.

@ktakashi
Created October 14, 2015 17:21
Show Gist options
  • Save ktakashi/03ae059f804a723a9589 to your computer and use it in GitHub Desktop.
Save ktakashi/03ae059f804a723a9589 to your computer and use it in GitHub Desktop.
Macro assoc
(import (scheme base) (scheme write))
(define-syntax assocm
(syntax-rules ()
((_ key (alist ...))
(letrec-syntax ((foo (syntax-rules (key)
((_ (key . e) res (... ...)) '(key . e))
((_ (a . d) res (... ...)) (foo res (... ...))))))
(foo alist ...)))))
(display (assocm c ((a . b) (b . d) (c . d) (d . d)))) (newline)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment