On Wed, Aug 08, 2012 at 09:19:15AM +0000, Samuel Lê wrote:
> Dear all,
> 
> I am trying to write some code that would take a function name, get its
> source code, and create a new function based on the source code.
> Unfortunately, the function 'source' from clojure.repl doesn't seem to be
> working for the functions I define.
> Here is my code:
> 
> (ns test-src.core
>   (:require [clojure.repl]))
> 
> (defn my-function [x]
>   (+ x 1))
> 
> (defn print-src []
>   (println (clojure.repl/source my-function)))
> 

Try:

    (defn print-src []
      (println (with-out-str (clojure.repl/source my-function))))

The "source" method is designed for the REPL, and so dumps to *out* by
default (you can confirm this yourself, appropriately enough, by doing
"(source source)")

Cheers,

Josh



-- 
Joshua Ballanco

ELC Technologies™
1771 NW Pettygrove Street, Suite 140
Portland, OR, 97209
jballa...@elctech.com

P +1 866.863.7365
F +1 877.658.6313
M +1 646.463.2673
T +90 533.085.5773

http://www.elctech.com

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

Reply via email to