Your best bet is to move your "system atom" out to a top-level def, like so:

(def system-atom (atom '({})))

Then just use (eval `(~afn system-atom)) later on, from places where the
system-atom Var is visible (same ns, or :use'd), or use (eval `(~afn
x/system-atom)) to qualify the name. The syntax quote will cause the eval'd
code to use a fully qualified name regardless.

If you don't want lots of stuff depending on a top-level singleton object
(say, because you might want to have two parallel tasks in the same JVM
with two different system-atoms), and can't get rid of eval, you can use a
top-level map:

(def system-atoms (atom {}))

(defn new-system-atom! [k]
  (swap! system-atoms assoc k (atom '({}))))

...

(new-system-atom! :foo) ... (eval `(~afn (:foo @system-atoms)))

...

(eval `(~bfn (:bar @system-atoms)))



On Fri, Jan 3, 2014 at 7:20 PM, Jason Wolfe <ja...@w01fe.com> wrote:

> Glad to help.
>
> I admittedly haven't taken the time to understand what's going on in your
> code, but whenever I see `eval` I feel compelled to ask: are you sure you
> need it?
>
> With that out of the way, here's a trick I've used to work around related
> errors:
>
> https://groups.google.com/d/msg/clojure/BZwinR2zNgU/8HGOgzOxzosJ
>
> Best,
> Jason
>
> On Friday, January 3, 2014 3:18:22 PM UTC-8, frye wrote:
>
>> Hey Jason,
>>
>> You were exactly right (which is pretty impressive, being that you've
>> never seen my code). In my (s/defn ..) form, there was an error that was
>> failing silently.
>>
>> (s/defn [one two]
>>    ...
>>    *#_(def params (atom '({}) ))*
>>    (def params '({}))
>>    (try (eval `(~afn ~@params))  (catch Exception e (println "Exception:
>> " (.getMessage e)))))
>>
>>
>> So the abouve code works. But if I instead use the commented version,
>> I'll get an exception. It seems there's a problem passing in a form
>> containing an atom to be dynamically eval'd. The error is mentioned on
>> these posts (here <http://clojure-log.n01se.net/date/2009-03-02.html>and
>> here <http://www.raynes.me/logs/irc.freenode.net/clojure/2012-09-17.txt#>).
>> Is there a way to pass in a form containing an atom to be dynamically
>> eval'd? It's pretty important to my architecture, that all functions treat
>> that system-atom the same. Any insights are welcome.
>>
>> *"java.lang.RuntimeException: Can't embed object in code, maybe print-dup
>> not defined: clojure.lang.Atom@1c99db7 (NO_SOURCE_FILE:0)"*
>>
>>
>>
>> Thanks
>>
>> Tim Washington
>> Interruptsoftware.com <http://interruptsoftware.com>
>>
>>
>> On Fri, Jan 3, 2014 at 2:39 PM, Jason Wolfe <ja...@w01fe.com> wrote:
>>
>>> Thanks for the report.
>>>
>>> Schema fns inside of go blocks seem to work fine for me.  It seems
>>> likely that you're seeing an exception inside the go block, which is
>>> swallowed by default:
>>>
>>> user> (clojure.core.async/go (println "A"))
>>> #<ManyToManyChannel clojure.core.async.impl.channels.ManyToManyChannel@
>>> 46ae10a6>
>>> A
>>>
>>> user> (clojure.core.async/go (throw (RuntimeException.)) (println "A"))
>>> #<ManyToManyChannel clojure.core.async.impl.channels.ManyToManyChannel@
>>> 427c78c1>
>>>
>>> Would you mind wrapping the body of your go block in a try/catch and
>>> printing the exception stack trace, or posting a gist that demonstrates the
>>> issue so I can look into it further?
>>>
>>> Thanks!
>>>
>>>
>>> On Friday, January 3, 2014 10:21:16 AM UTC-8, frye wrote:
>>>
>>>> Forwarding...
>>>>
>>>> ---------- Forwarded message ----------
>>>> From: Timothy Washington <twas...@gmail.com>
>>>> Date: Fri, Jan 3, 2014 at 1:17 PM
>>>> Subject: Re: Core.async, Rules for passing clojure vals to go block
>>>> To: Shaun Gilchrist <shaun...@gmail.com>
>>>>
>>>>
>>>> I'm using Prismatic's Schema in my code base. Now, it looks like
>>>> defining some functions with 
>>>> s/defn<https://github.com/Prismatic/schema/blob/master/src/clj/schema/macros.clj#L453>,
>>>> yields some wonky behaviour. Particularly, not running, when being invoked
>>>> in a go block. It just fails silently, which is why it was so hard to track
>>>> down. Don't yet know why this is happening. But an fyi for the devs and
>>>> users of this package. Still love schema, I just need to figure out where
>>>> the call chain breaks down.
>>>>
>>>>
>>>> Hth
>>>>
>>>> Tim Washington
>>>> Interruptsoftware.com <http://interruptsoftware.com>
>>>>
>>>>
>>>> On Fri, Jan 3, 2014 at 9:58 AM, Timothy Washington 
>>>> <twas...@gmail.com>wrote:
>>>>
>>>>> Hey Shaun,
>>>>>
>>>>> Thanks for looking into this. Your example does indeed work. I'll have
>>>>> to teardown my own code and see where the invocations are failing. At 
>>>>> least
>>>>> I know it's not core.async.
>>>>>
>>>>>
>>>>> Cheers
>>>>>
>>>>> Tim Washington
>>>>> Interruptsoftware.com <http://interruptsoftware.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
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to