Received: by 10.101.97.12 with SMTP id z12mr3131478anl.15.1305005537782;
Mon, 09 May 2011 22:32:17 -0700 (PDT)
X-BeenThere: clojure@googlegroups.com
Received: by 10.101.173.23 with SMTP id a23ls780398anp.7.gmail; Mon, 09 May
2011 22:32:08 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.100.60.2 with SMTP id i2mr786564ana.13.1305005528669; Mon, 09
May 2011 22:32:08 -0700 (PDT)
Received: by g12g2000yqd.googlegroups.com with HTTP; Mon, 9 May 2011 22:32:08
-0700 (PDT)
Date: Mon, 9 May 2011 22:32:08 -0700 (PDT)
In-Reply-To: <4ac942c4-bd23-495d-9706-14d6e327e3ac@d15g2000yqn.googlegroups.com>
X-IP: 74.74.238.42
References: <4ac942c4-bd23-495d-9706-14d6e327e3ac@d15g2000yqn.googlegroups.com>
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_7)
AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.57 Safari/534.24,gzip(gfe)
Message-ID: <8ae55f26-0a4c-40b2-b92b-727668530c7d@g12g2000yqd.googlegroups.com>
Subject: Re: Ok, so code is data...
From: Justin Kramer <jkkra...@gmail.com>
To: Clojure <clojure@googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
'read' and 'read-string' are what you're looking for. They each read a
single Clojure object from an input source (PushbackReader for read,
String for read-string).
Alternatively, something like this can read all top-level forms from a
file:
(defn read-all
"Reads all top-level forms from f, which will be coerced by
clojure.java.io/reader into a suitable input source. Not lazy."
[f]
(with-open [pbr (java.io.PushbackReader. (clojure.java.io/reader
f))]
(doall
(take-while
#(not=3D ::eof %)
(repeatedly #(read pbr false ::eof))))))
(read-all "/some/clojure/file.clj")
=3D> ((foo :bar) (baz))
Justin
On May 9, 11:36=A0pm, Bill Robertson <billrobertso...@gmail.com> wrote:
> How do I actually manipulate it? =A0I have some complicated logic that I
> would like to transform into html (or maybe xml) for display
> purposes.
>
> I'm generating the Clojure code by parsing some nasty Java and
> outputting s-expressions. =A0The Java is basic, but quite deeply
> nested. =A0I want to generate working Clojure to demonstrate what that
> can do for us, and get this nastiness documented of course.
>
> Other than going into the source files and transforming it by hand
> into a series of defs and quoted lists e.g. =A0(def my_func '(+ 1 2))
> How do I actually just load code w/o evaluating it?
>
> I've found the pretty printer macros, seems like that might be useful
> if I wanted to statically transform the code. =A0I found the walker,
> that looks like it might be useful in actually generating the output
> (e.g. visit things, spit out (x|ht)ml.
>
> I looked at the various load functions in clojure.core. =A0With the
> exception of load (http://clojure.github.com/clojure/clojure.core-
> api.html#clojure.core/load) they all seem to load and evaluate. =A0Is
> load the answer or is it something I haven't found yet?
>
> Once I get the code loaded, I don't think I need anything out of the
> ordinary like macros or multi-methods. =A0I think I can just manipulate
> the lists. =A0Does that sound correct?
>
> I'm sorry if this are a stupid questions, but I've never done anything
> in Clojure of any significance, and any helpful answers you provide
> would could save me days of stumbling about.
>