I certainly like that better than the binding solution, especially if
hotspot can potentially inline the functions. It still tricky to do
that in a macro, especially when the code to be evaled depends on the
current lexical scope, but I can maybe work around that. Thanks.
On 29 August 2013 04:50,
Sounds interesting, I'd love to hear more about the use case.
We ran into this issue as well when implementing the new positional
compilation for Graph. We filed a ticket [1], and worked around it with a
funny trick:
Suppose you want to eval a complicated thing, and the crux of the issue is
Weak references do work, and it looks like I can just stuff values into a
single java.util.WeakHashMap under gensym-generated keys and not worry
about polluting namespaces. Still kind of hacky, but seems to work.
On Wed, Aug 28, 2013 at 10:28 AM, Jamie Brandon <
ja...@scattered-thoughts.net> wrot
Sorry, I guess that wasn't very clear. Let's put a really simple
example with just the pattern-matching subset:
strucjure.regression.sandbox=> (def p (pattern [1 ^x _ 3]))
#'strucjure.regression.sandbox/p
strucjure.regression.sandbox=> p
[1 #strucjure.pattern.Bind{:symbol x, :pattern #strucjure.p
This is a little hard for me to follow because I'm not sure what graph or
output-in are doing.
If the letfn is being generated by your compilation step, why can't that go
inside of your generated fn rather than outside it?
(clojure.core/fn
[input__2288__auto__]
(clojure.core/letfn
[(nu
Yeah, as far as I can tell eval can't emit pointers so we can't pass
closures or references at all except by indirection through an
existing singleton (like a named var).
On 28 August 2013 19:34, Aaron Cohen wrote:
> Sorry, that one doesn't work. It worked in my repl, but I must have been
> using
Sorry, that one doesn't work. It worked in my repl, but I must have been
using old code.
On Wed, Aug 28, 2013 at 2:27 PM, Aaron Cohen wrote:
> How about this alternative?
>
> (deftype Wrapper [f]
> clojure.lang.IFn
> (invoke [this] (f))
> (invoke [this a] (f a))
> ; repeat until you get
How about this alternative?
(deftype Wrapper [f]
clojure.lang.IFn
(invoke [this] (f))
(invoke [this a] (f a))
; repeat until you get bored
)
(defn e [f]
(let [wr (Wrapper. f)]
(eval `(~wr 1
(e inc)
(e (with-meta (fn [x] (+ 4 x)) {}))
On Wed, Aug 28, 2013 at 1:59 PM, Jamie B
That sort of works for my use case.
What I want to do is define a grammar...
(def num-graph
(graph
num ~(or ~succ ~zero)
succ (succ ^x ~num)
zero zero))
... attach actions
(def num-out
(output-in num-graph
'zero (fnk [] 0)
'succ (fnk [x] (inc x
... and com
I'm not sure if you'll consider this hacky or not.
(def ^:dynamic *fn-helper*)
(defn eval-at-one [f] (binding [*fn-helper* f] (eval '(*fn-helper* 1
On Wed, Aug 28, 2013 at 1:28 PM, Jamie Brandon wrote:
> You will also run into problems if your functions close over any data:
>
> user> (le
You will also run into problems if your functions close over any data:
user> (let [f (fn [] 1)] (eval `(~f)))
1
nil
user> (let [x 1 f (fn [] x)] (eval `(~f)))
IllegalArgumentException No matching ctor found for class
user$eval38616$f__38617 clojure.lang.Reflector.invokeConstructor
(Reflector.java
On Wed, Aug 28, 2013 at 9:27 AM, Jamie Brandon wrote:
>
> If you aren't worried about leaking memory, a possible workaround is
> to intern the fn in some namespace and then put the symbol in the
> macro output.
>
Hrm, I hope it doesn't come to that---as long as I'm creating the functions
with th
Clojure struggles with staged programming because of JVM limitations.
"The deeper issue here is that JVM bytecode is fundamentally static:
it's not allowed to contain references to objects that only exist at
runtime. In languages that have a built-in concept of a "runtime
image," like Smalltalk o
On Wed, Aug 28, 2013 at 2:46 AM, Gary Fredericks
wrote:
> what's the use case for evaling a function object?
>
This is just a minimal example that illustrates the difficulty, in the
actual code where I came across it, a new function with relatively complex
internals is created at runtime.
--
Be
what's the use case for evaling a function object?
On Tue, Aug 27, 2013 at 8:54 PM, Ben Wolfson wrote:
> or, the dreaded "no matching ctor found" exception.
>
> Is there a way to write the function
>
> (defn eval-at-one [f] (eval `(~f 1)))
>
> such that it works when invoked like this:
>
> (eva
15 matches
Mail list logo