Re: Homoiconicity and printing functions

2009-07-09 Thread Richard Newman
That was easy! user=> (defmacro metafn [meta args & body] `(proxy [clojure.lang.AFn] [~meta] (invoke ~args ~...@body))) #'user/metafn user=> (metafn {:foo :bar} [a b c] (println a) (+ a b c)) # user=> (*1 1 2 3) 1 6 user=> (meta (metafn {:foo :bar} [a b c] (println a) (+ a b c))) {:foo :bar

Re: Homoiconicity and printing functions

2009-07-09 Thread Richard Newman
> Actually, it does. Ah, that explains the UnsupportedOperationException :) > user=> (instance? clojure.lang.IMeta (fn [])) > true > > What it doesn't support is changing the metadata after > creation: > > user=> (with-meta (fn []) {:foo "bar"}) > java.lang.UnsupportedOperationException (NO_SOUR

Re: Homoiconicity and printing functions

2009-07-09 Thread Chouser
On Thu, Jul 9, 2009 at 4:19 PM, Richard Newman wrote: > > Is there any particular reason why Fn doesn't implement IMeta? Actually, it does. user=> (instance? clojure.lang.IMeta (fn [])) true What it doesn't support is changing the metadata after creation: user=> (with-meta (fn []) {:foo "bar"}

Re: Homoiconicity and printing functions

2009-07-09 Thread Richard Newman
> If you want to be able to query a function for its source code later > on, that's tougher. You'll need to make a macro that wraps defn and > assigns a copy of the body form to a metadata tag on the function's > name. I'm resurrecting this thread because I'm actually hitting this problem

Re: Homoiconicity and printing functions

2009-07-09 Thread Mike
On Jul 8, 12:47 pm, Meikel Brandmeyer wrote: > Hi, > > I'd like to second the suggestion of Richard and Daniel (in > the other thread): use a file. > > It solves almost all problems with immediate effect. > > Here is my workflow for your example. I added some > annotations. (as a note: I use VimC

Re: Homoiconicity and printing functions

2009-07-08 Thread Meikel Brandmeyer
Hi, I'd like to second the suggestion of Richard and Daniel (in the other thread): use a file. It solves almost all problems with immediate effect. Here is my workflow for your example. I added some annotations. (as a note: I use VimClojure for development) Am 08.07.2009 um 16:39 schrieb Mike:

Re: Homoiconicity and printing functions

2009-07-08 Thread Phil Hagelberg
Mike writes: > I'm using that JLine thing for command history, but I would imagine > it's completely oblivious to Clojure forms so they get split > (potentially, depending on how I typed it) on multiple lines. It's easy to get in a state where you're not sure how to reproduce it if you enter a

Re: Homoiconicity and printing functions

2009-07-08 Thread Richard Newman
> How do folks interactively code with a REPL and then once things > "settle down" dump it back out so you can make a proper module out of > it? Typically, folks don't. Use Vim, Emacs, Eclipse... any tool that provides an interactive Clojure toplevel and the ability to evaluate forms within fi

Re: Homoiconicity and printing functions

2009-07-08 Thread Mike
On Jul 8, 10:14 am, "Stephen C. Gilardi" wrote: > Once it's compiled, it's JVM bytecode. I'm not aware of a tool that   > could decompile it into Clojure code, even in a low-level form. That's what I was afraid of. How do folks interactively code with a REPL and then once things "settle down" d

Re: Homoiconicity and printing functions

2009-07-08 Thread John Harrop
On Wed, Jul 8, 2009 at 9:11 AM, Mike wrote: > One of the things that drew me to Clojure was the fact that it's > homoiconic (and my previous lisp [Scheme] was not necessarily), which > means code is data, macro writing is easy etc. etc. > > What I'm missing is why I can't print a function. I und

Re: Homoiconicity and printing functions

2009-07-08 Thread Stephen C. Gilardi
On Jul 8, 2009, at 9:11 AM, Mike wrote: What I'm missing is why I can't print a function. I understand that most of the functions I write use quite a few macros, and after expansion into the core forms it looks shredded...but isn't there any way for me to see a representation of this "source"

Homoiconicity and printing functions

2009-07-08 Thread Mike
One of the things that drew me to Clojure was the fact that it's homoiconic (and my previous lisp [Scheme] was not necessarily), which means code is data, macro writing is easy etc. etc. What I'm missing is why I can't print a function. I understand that most of the functions I write use quite a