Greg's is a nice and clean solution for the data visualization problem, 
assuming you're only going to use partials.

I hacked together a solution to support functions with equality semantics, 
if anyone is interested. It doesn't support anonymous functions or 
closures, but doing that would require some advanced macro magic and I 
don't want to invest the time in that now. Below is an example of usage - 
the source is on my 
Github<https://github.com/matvore/hesokuri/blob/9488ff4877c71f861660a524e86791db8fab76ce/src/hesokuri/util.clj#L131>
.

(defnv adder [value] [another-num]
  (+ value another-num))

(defnv exclaimer [bangs mark] [phrase]
  (apply str phrase (repeat bangs mark)))

(def adder-4 (adder 4))
(def adder-0 (adder 0))
(def exclaimer-?? (exclaimer 2 "?"))

(deftest test-defnv-equality
  (is (= (adder 1) (adder 1)))
  (is (not= (exclaimer 2 "!") exclaimer-??)))

(deftest test-defnv-invocation
  (is (= 4 (adder-4 0)))
  (is (= 44 (adder-0 44)))
  (is (= 55 (adder-4 51)))
  (is (= "Hello??" (exclaimer-?? "Hello"))))

(deftest test-defnv-print-method
  (are [expected vfn]
       (let [w (new java.io.StringWriter)]
         (print-method vfn w)
         (= expected (str w)))
       "(adder 0)" adder-0
       "(adder 4)" adder-4
       "(exclaimer 2 \"?\")" exclaimer-??))


在 2014年4月26日星期六UTC-7上午5时27分37秒,Greg D写道:
>
> Simpler yet using metadata:
> (ns example.ppfn)
>
> (defn print-pf [pf]
>   (if-let [ppf (::ppf (meta pf))] ppf pf))
>
> (defmacro partial* [& args]
>   `(let [m#  (pr-str '(partial* ~@args))
>          pf# (with-meta (partial ~@args) {::ppf m#})]
>      (defmethod print-method (class pf#) [o# w#] (print-simple 
> (example.ppfn/print-pf o#) w#))
>      pf#))
>
> In use:
> user=> (def p1 (partial* + 1))
> #'user/p1
> user=> (p1 5)
> 6
> user=> p1
> (example.ppfn/partial* + 1)
> user=> (def comma-join (partial* clojure.string/join ", "))
> #'user/comma-join
> user=> (comma-join ['a 'b 'c])
> "a, b, c"
> user=> comma-join
> (example.ppfn/partial* clojure.string/join ", ")
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to