I am working on web software where admins will be using HTML forms to 
update data in a MongoDb database. I decided to use Lamina to off-load the 
work to the background. There are several operations that need to happen: 
updates, deletions, etc, and I thought I'd put each on a different channel. 
So I tried to write a macro to generate the code needed for each of those 
channels. This was my first attempt: 

(defmacro establish-channel [action noun to-execute start-function-name]
  (let [channel-name (symbol (str "documents-to-" action "-in-" noun 
"-channel"))
        additive-action-name (symbol (str "add-to-" action "-channel"))
        worker-name (symbol (str action "-" noun "-worker"))]

  `(def ~channel-name (channel))

  `(defn ~additive-action-name [document]
     (enqueue ~channel-name document))

  `(defn ~worker-name []
     (loop [document @(read-channel ~channel-name)]
       (~to-execute document)
       (recur @(read-channel ~channel-name))))
  
  `(defn ~start-function-name []
     (future (~worker-name))
     (future (~worker-name))
     (future (~worker-name))
     (future (~worker-name))
     (future (~worker-name)))))


But in the repl, when I run this, and then I do this:

user> (macroexpand-1 (establish-channel update mongo println 
start-mongo-channel))

I get: 

CompilerException java.lang.RuntimeException: Unable to resolve symbol: 
update-mongo-worker in this context, compiling:(NO_SOURCE_PATH:1:16) 

It seems to be complaining about this line:

     (future (~worker-name))

But I defined that function just above that line: 

  `(defn ~worker-name []

So what could the problem be? 

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