Re: Access the datastructure used to create a function?

2014-05-01 Thread henry w
related to this discussion and v. interesting: http://blog.guillermowinkler.com/blog/2014/04/27/decompiling-clojure-iii/ On Tuesday, November 26, 2013 10:04:12 PM UTC, Guru Devanla wrote: The important caveat here is what do we label as data?. If we are okay with just 'streams of bytes'

Re: Access the datastructure used to create a function?

2013-11-26 Thread henry w
Sad not to get any replies - even to tell me if it is a bad idea or not possible. :-( Assuming it is not possible, am I right in saying that at the moment, in Clojure, 'code is data' really only applies until code is compiled? I realise compiled functions can still be passed around, assigned

Re: Access the datastructure used to create a function?

2013-11-26 Thread Max Penet
The best you can do is probably mess with https://github.com/technomancy/serializable-fn, but maybe trying to describe what you are trying to do at a higher level would help, most of the time using serializable-fn is a bad idea (symptom of one). On Thursday, November 21, 2013 7:14:39 PM

Re: Access the datastructure used to create a function?

2013-11-26 Thread Guru Devanla
Hi, This may not be the answer you are looking for. But, kooking at the example you gave, you will need to execution environment of the function to determine the binding of y. It could vary based on where it is invoked. That is because, if the function call was wrapped inside a 'binding form then

Re: Access the datastructure used to create a function?

2013-11-26 Thread Jamie Brandon
(def f (let [y 1] (fn [x] (+ x y Let's have a look inside. (require '[no.disassemble :refer [disassemble]]) (println (disassemble f)) // Compiled from /home/jamie/strucjure/src/strucjure.clj (version 1.5 : 49.0, super bit) public final class strucjure$fn__5589$fn__5590 extends

Re: Access the datastructure used to create a function?

2013-11-26 Thread Guru Devanla
Hi Jamie, Thats interesting. How do I not let the compiler not optimize away the fact that y refers to the constant. When I run your program I have two constant fields defined rather than 'y. Am I missing something. Thanks Guru On Tue, Nov 26, 2013 at 6:16 AM, Jamie Brandon

Re: Access the datastructure used to create a function?

2013-11-26 Thread Jamie Brandon
Guru, I'm not sure. Are you running it exactly the same way? If you did... (def y 1) (def f (fn [x] (+ x y))) ...then I think that would result in two const fields instead, because it stores the var #'y as a static field and calls getRawRoot on it at runtime. Otherwise I'm not sure. On 26

Re: Access the datastructure used to create a function?

2013-11-26 Thread Alex Miller
It would help to know what your real goal is, but compiled Clojure does not retain the original source form. One hook you do have though is macros which will be invoked prior to compilation. At macro execution time, you have access to the special form var which is the original form (as a

Re: Access the datastructure used to create a function?

2013-11-26 Thread Gary Verhaegen
I think that is basically what serializable-fn does. Might be worth taking a look at it: https://github.com/technomancy/serializable-fn/blob/master/src/serializable/fn.clj On Tuesday, 26 November 2013, Alex Miller wrote: It would help to know what your real goal is, but compiled Clojure does

Re: Access the datastructure used to create a function?

2013-11-26 Thread Alex Miller
Seems like you lost the clojure mailing list in this response, so I re-added it. On Tue, Nov 26, 2013 at 2:09 PM, henry w henryw...@gmail.com wrote: Thanks to all respondents. This was really just something I was curious about, although I can think of some practical uses. It's just not

Re: Access the datastructure used to create a function?

2013-11-26 Thread henry w
The thing is, the data contained in the source definition is all still there in the compiled version - but apparently it is not easily accessible. It feels like it must be possible to write a function that looks at a function object and it's class and can produce at least a decent

Re: Access the datastructure used to create a function?

2013-11-26 Thread Guru Devanla
The important caveat here is what do we label as data?. If we are okay with just 'streams of bytes' that will make us understand and reason some information about the function, then may be the bytecode itself could be sufficient and could be considered to be data. But, I guess the original

Access the datastructure used to create a function?

2013-11-21 Thread henry w
Say you have a function created like this: (fn [x] (+ x y)) and then you have a reference to an instance of this function, is there some way to use the function reference to access the list '(fn [x] (+ x y)), including the symbol 'y' (such that you could dereference 'y' and get its value)? The