Skip to content

Instantly share code, notes, and snippets.

@jayp
Last active August 29, 2015 14:11
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 jayp/ece9035fea0aa2d31926 to your computer and use it in GitHub Desktop.
Save jayp/ece9035fea0aa2d31926 to your computer and use it in GitHub Desktop.
How does one writhe add-params-to-func?
repl=> (defmacro add-params [expr & params]
#_=> `(~@expr ~@params))
;; add-params works as intended for regular functions
repl=> (macroexpand '(add-params (+ 5 6) 7 8 9))
(+ 5 6 7 8 9)
repl=> (add-params (+ 1 2) 3 4 5)
15
;; add-params does not work if expr is a function
repl=> (macroexpand '(add-params #(+ %1 %2) 3 4 5))
(fn* [p1__14703# p2__14704#] (+ p1__14703# p2__14704#) 3 4 5)
;; I want another macro called add-params-to-func.
;; To be precise, I want the following to expand to:
;;
;; repl=> (macroexpand '(add-params-to-func #(+ %1 %2) 3 4 5))
;; (fn* [p1__14703# p2__14704#] (+ p1__14703# p2__14704# 3 4 5))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Below is a simplified version of the code where I need to use add-params-to-func
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(let [valid-user "john.doe@example.com"
send-email #(post-webhook %1 :from %2)
email-user #(send-email % valid-user)
;; FIXME: use add-params-to-func to leverage code re-use with email-user
email-user-with-signature #(post-webhook %1 :from valid-user :signature %2)]
(testing "send-email to random user"
(let [response1 (send-email (new-request) "random@example.com")
response2 (email-user (new-request))
response3 (email-user-with-signature (new-request) "c5b28dba418830bd")])))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment