Re: Pretty print defn

2012-03-12 Thread Cedric Greevey
On Thu, Mar 8, 2012 at 1:47 PM, Jeff Weiss jeffrey.m.we...@gmail.com wrote:
 A serializable.fn/defn would be really nice to have, I am not sure how
 difficult it would be to write, without having tried it.

In theory, not very difficult. Something like

(defmacro defn [name  everything-else]
  `(clojure.core/defn
 ~(with-meta name {:source `(defn ~name ~@everything-else)})
 ~@everything-else))

(which gets clojure.core/defn to do all of the heavy lifting) should
work if putting the metadata on the Var suffices.

-- 
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


Re: Pretty print defn

2012-03-08 Thread Jeff Weiss
I use serializable.fn pretty extensively, and it's been working great for 
me.  I think at this point, the only fix I put in that Phil didn't is that 
my serialized fn's print with an unqualified fn symbol, instead of 
serializable.fn/fn.  I did that so it's more readable, the tradeoff is 
that if you want your fn's to be re-serializable (which I don't think you 
do), you have to spell out which fn you're using.

https://github.com/weissjeffm/serializable-fn

Another caveat is that it does not work with defn, just fn.  So you would 
have to do 
(def qw  
 (fn [] 
  (inc 2)) 

A serializable.fn/defn would be really nice to have, I am not sure how 
difficult it would be to write, without having tried it.

-jeff

On Friday, March 2, 2012 10:19:56 PM UTC-5, Phil Hagelberg wrote:

 Mark Rathwell mark.rathw...@gmail.com writes:

  (clojure.repl/source-fn 'qw) will give you the source.

 You can also use serializable-fn to create a function that will carry
 its source around with it in metadata:

 https://github.com/technomancy/serializable-fn

 But it's not very well tested.

 -Phil



-- 
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

Re: Pretty print defn

2012-03-06 Thread Nikem
Thank you for your help! :)

I managed to get repl/source-fn to read source from external namespace. But 
print gives me
(defn buy? [today]\n  (and\n(not (nil? today))\n

Everything on one line with \n instead of new lines. Shouldn't pretty 
print handle this?

Best wishes
Nikem

On Tuesday, March 6, 2012 12:32:28 AM UTC+2, Phil Hagelberg wrote:

 Nikem gni...@gmail.com writes:

   java -jar lib/clojure-1.3.0.jar 
  user= (defn qw []
(inc 2))
  #'user/qw
  user= (use 'clojure.repl)
  nil
  user= (clojure.repl/source-fn qw)
  ClassCastException user$qw cannot be cast to clojure.lang.Symbol
   clojure.core/ns-resolve (core.clj:3879)
  user= (clojure.repl/source-fn 'qw)
  nil
  user= (println (clojure.repl/source-fn 'qw))
  nil
  nil
  user=
 
  What am I doing wrong?

 source will only check for definitions on disk; you need serializable-fn
 for something like this to work.

 -Phil



-- 
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

Re: Pretty print defn

2012-03-06 Thread Mark Rathwell
If you are just printing it to the screen, print or println will do
what you want.  There shouldn't be a need for a pretty printer, the
source is already formatted exactly as it was written.


On Tue, Mar 6, 2012 at 1:02 AM, Nikem gni...@gmail.com wrote:
 Thank you for your help! :)

 I managed to get repl/source-fn to read source from external namespace. But
 print gives me
 (defn buy? [today]\n  (and\n    (not (nil? today))\n    

 Everything on one line with \n instead of new lines. Shouldn't pretty
 print handle this?

 Best wishes
 Nikem


 On Tuesday, March 6, 2012 12:32:28 AM UTC+2, Phil Hagelberg wrote:

 Nikem gni...@gmail.com writes:

   java -jar lib/clojure-1.3.0.jar
  user= (defn qw []
    (inc 2))
  #'user/qw
  user= (use 'clojure.repl)
  nil
  user= (clojure.repl/source-fn qw)
  ClassCastException user$qw cannot be cast to clojure.lang.Symbol
   clojure.core/ns-resolve (core.clj:3879)
  user= (clojure.repl/source-fn 'qw)
  nil
  user= (println (clojure.repl/source-fn 'qw))
  nil
  nil
  user=
 
  What am I doing wrong?

 source will only check for definitions on disk; you need serializable-fn
 for something like this to work.

 -Phil

 --
 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 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


Re: Pretty print defn

2012-03-05 Thread Nikem
 java -jar lib/clojure-1.3.0.jar 
user= (defn qw []
  (inc 2))
#'user/qw
user= (use 'clojure.repl)
nil
user= (clojure.repl/source-fn qw)
ClassCastException user$qw cannot be cast to clojure.lang.Symbol 
 clojure.core/ns-resolve (core.clj:3879)
user= (clojure.repl/source-fn 'qw)
nil
user= (println (clojure.repl/source-fn 'qw))
nil
nil
user=

What am I doing wrong?

On Saturday, March 3, 2012 4:18:35 AM UTC+2, Mark Rathwell wrote:

 (clojure.repl/source-fn 'qw) will give you the source.

 On Fri, Mar 2, 2012 at 10:32 AM, Nikem gni...@gmail.com wrote:
  Hi.
 
  Is it possible to pretty print a source code of the function defined
  with defn? I have tried the following:
 
  (defn qw []
   (inc 2))
 
  (with-pprint-dispatch code-dispatch (pprint qw))
 
  And got #user$qw user$qw@4743bf3d. But I would like to get at least
  (inc 2). Is it possible at all?
 
  Nikem
 
  --
  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 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

Re: Pretty print defn

2012-03-05 Thread Phil Hagelberg
Nikem gni...@gmail.com writes:

  java -jar lib/clojure-1.3.0.jar 
 user= (defn qw []
   (inc 2))
 #'user/qw
 user= (use 'clojure.repl)
 nil
 user= (clojure.repl/source-fn qw)
 ClassCastException user$qw cannot be cast to clojure.lang.Symbol
  clojure.core/ns-resolve (core.clj:3879)
 user= (clojure.repl/source-fn 'qw)
 nil
 user= (println (clojure.repl/source-fn 'qw))
 nil
 nil
 user=

 What am I doing wrong?

source will only check for definitions on disk; you need serializable-fn
for something like this to work.

-Phil

-- 
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


Pretty print defn

2012-03-02 Thread Nikem
Hi.

Is it possible to pretty print a source code of the function defined
with defn? I have tried the following:

(defn qw []
  (inc 2))

(with-pprint-dispatch code-dispatch (pprint qw))

And got #user$qw user$qw@4743bf3d. But I would like to get at least
(inc 2). Is it possible at all?

Nikem

-- 
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


Re: Pretty print defn

2012-03-02 Thread Mark Rathwell
(clojure.repl/source-fn 'qw) will give you the source.

On Fri, Mar 2, 2012 at 10:32 AM, Nikem gni...@gmail.com wrote:
 Hi.

 Is it possible to pretty print a source code of the function defined
 with defn? I have tried the following:

 (defn qw []
  (inc 2))

 (with-pprint-dispatch code-dispatch (pprint qw))

 And got #user$qw user$qw@4743bf3d. But I would like to get at least
 (inc 2). Is it possible at all?

 Nikem

 --
 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 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


Re: Pretty print defn

2012-03-02 Thread Phil Hagelberg
Mark Rathwell mark.rathw...@gmail.com writes:

 (clojure.repl/source-fn 'qw) will give you the source.

You can also use serializable-fn to create a function that will carry
its source around with it in metadata:

https://github.com/technomancy/serializable-fn

But it's not very well tested.

-Phil

-- 
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