Created
December 14, 2012 06:55
-
-
Save Beyamor/4283258 to your computer and use it in GitHub Desktop.
Argument inferencer source.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns infer-arg.core | |
(:use [clojure.core.incubator :only [-?>]])) | |
(defn make-wrapper-fn | |
[symbolic-arg-list] | |
(eval | |
`(fn [f# {:keys ~symbolic-arg-list}] | |
(f# ~@symbolic-arg-list)))) | |
(defn inference-wrapper | |
[f] | |
(if-let [arg-list (-?> f meta :arg-list)] | |
(let [symbolic-arg-list (vec (map #(-> % name symbol) arg-list))] | |
(partial | |
(make-wrapper-fn symbolic-arg-list) | |
f)) | |
f)) | |
(defmacro fn|arg-list | |
[args & body] | |
(let [arg-list (vec (map keyword args))] | |
`(with-meta | |
(fn ~args ~@body) | |
{:arg-list ~arg-list}))) | |
(defmacro defn|arg-list | |
[sym args & body] | |
`(def ~sym (fn|arg-list ~args ~@body))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment