Skip to content

Instantly share code, notes, and snippets.

@qbg
Created December 19, 2010 23:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save qbg/747841 to your computer and use it in GitHub Desktop.
Save qbg/747841 to your computer and use it in GitHub Desktop.
(defsyntax-rules plet
(plet [& var rhs] & body)
((fn [& var] & body) & rhs))
(plet [a 1 b 2] (+ a b)) ;=> 3
;;; Implementation of defsyntax-rules
; Using defmacro:
(defmacro defsyntax-rules
[name & rt-pairs]
(let [rules (take-nth 2 rt-pairs)
templates (take-nth 2 (rest rt-pairs))]
`(let [ar# (make-apply-rules '~rules '~templates)]
(defmacro ~name
[& forms#]
(ar# (cons '~name forms#))))))
; Using defsyntax-rules:
(defsyntax-rules defsyntax-rules
(defsyntax-rules name & rule template)
(let [ar (make-apply-rules '(& rule) '(& template))]
(defmacro name
[(+literal &) forms]
(ar (cons 'name forms)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment