Improving pprint behavior for anonymous functions

2014-04-25 Thread Matthew DeVore
Hi, There has been one thing bugging me for a long time that seems worth it to fix, and I was wondering if anyone else has had the same problem. I have enjoyed using Clojure's REPL and embracing a Clojure-style data model for my app, where everything is a glorified map or vector and there are n

Re: Improving pprint behavior for anonymous functions

2014-04-25 Thread Alex Miller
You might be interested in this ticket (http://dev.clojure.org/jira/browse/CLJ-1278) of which this is perhaps one special case. I don't know that I necessarily would want the equality semantics; at least in the case of impure functions the equality does not hold. On Friday, April 25, 2014 11:

Re: Improving pprint behavior for anonymous functions

2014-04-25 Thread Matthew DeVore
Thanks for pointing out the ticket, but based on the Description, it falls short of what I need. It doesn't have any additional information that I can't deduce from looking at the code, in other words, the value of the items in the closures. So while it makes toString prettier, it's not informa

Re: Improving pprint behavior for anonymous functions

2014-04-25 Thread Alex Miller
On Friday, April 25, 2014 1:23:49 PM UTC-5, Matthew DeVore wrote: > > Thanks for pointing out the ticket, but based on the Description, it falls > short of what I need. It doesn't have any additional information that I > can't deduce from looking at the code, in other words, the value of the >

Re: Improving pprint behavior for anonymous functions

2014-04-25 Thread Greg D
I don't know if this is considered good Clojure, but you could define a print-method within a macro to set up the normal string representation for the partial function: (defmacro partial* [fname arg0 & args] `(let [pf# (partial ~fname ~arg0 ~@args) cpf# (class pf#)] (defmethod pr

Re: Improving pprint behavior for anonymous functions

2014-04-25 Thread Gary Trakhman
That's not going to work, all the return classes of partial are the same class. On Fri, Apr 25, 2014 at 5:26 PM, Greg D wrote: > I don't know if this is considered good Clojure, but you could define a > print-method within a macro to set up the normal string representation for > the partial fun

Re: Improving pprint behavior for anonymous functions

2014-04-25 Thread Greg D
I guess I don't understand the problem, or what is meant by "different classes". A counter-example would be helpful. Further transcript using the macro: (def p6 (partial* + 1 2 3)) #'user/p6 user=> (class p6) clojure.core$partial$fn__4194 user=> (def p10 (partial* + 1 2 3 4)) #'user/p10 user=> (

Re: Improving pprint behavior for anonymous functions

2014-04-25 Thread Gary Trakhman
Ah, I think I was mistaken in a detail, but generally correct. Try it with two partials of the same arity. https://github.com/clojure/clojure/blob/master/src/clj/clojure/core.clj#L2460 On Fri, Apr 25, 2014 at 5:47 PM, Greg D wrote: > I guess I don't understand the problem, or what is meant by

Re: Improving pprint behavior for anonymous functions

2014-04-25 Thread Greg D
I guess I don't understand the problem, or what is meant by "all the return classes of partial are the same class". A counter-example would be helpful. Further transcript using the macro: user=> (def p6 (partial* + 1 2 3)) #'user/p6 user=> (class p6) clojure.core$partial$fn__4194 user=> (def p10

Re: Improving pprint behavior for anonymous functions

2014-04-25 Thread Gary Trakhman
user> (def a (partial* + 1 2 3)) #'user/a user> a (partial + 1 2 3) user> (def b (partial* + 1 2 5)) #'user/b user> b (partial + 1 2 5) user> a (partial + 1 2 5) On Fri, Apr 25, 2014 at 5:51 PM, Greg D wrote: > I guess I don't understand the problem, or what is meant by "all the > return c

Re: Improving pprint behavior for anonymous functions

2014-04-25 Thread Greg D
Got it. The macro, as is, will displace the print method for the same arity. On Friday, April 25, 2014 2:50:34 PM UTC-7, Gary Trakhman wrote: > > Ah, I think I was mistaken in a detail, but generally correct. Try it > with two partials of the same arity. > > > https://github.com/clojure/clojure/

Re: Improving pprint behavior for anonymous functions

2014-04-25 Thread Greg D
The code below accounts for partials of the same arity. However, there might be a better way to do this with clojure.reflect: (defn print-partial [a-fn] (let [c (class a-fn) fields (into {} (->> c .getDeclaredFields (map #(vector (.getName %)

Re: Improving pprint behavior for anonymous functions

2014-04-25 Thread Matthew DeVore
在 2014年4月25日星期五UTC-7下午12时16分22秒,Alex Miller写道: > > > On Friday, April 25, 2014 1:23:49 PM UTC-5, Matthew DeVore wrote: >> >> Thanks for pointing out the ticket, but based on the Description, it >> falls short of what I need. It doesn't have any additional information that >> I can't deduce from

Re: Improving pprint behavior for anonymous functions

2014-04-26 Thread 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 (

Re: Improving pprint behavior for anonymous functions

2014-04-26 Thread Matthew DeVore
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 requir