Hi guys, first I'm really noob using macros, basically I've this

(<!b (function-blah "hi"))

Hey..I didn't know than intellij copy/paste the text with format!..cool!

Ok..returning to my question...I don't need call to function-blah...I need 
send a message to one address possibly named "<some-namespace:blah"..how I 
discover which is the correct namespace is simple...I send a message to 
every possible namespace stored in a vector..when some bus return a 
response, I index it in a map (:function full-address) ...next calls only 
needs find the correct address in the map and send the message... 

just now I've this code:

(defmacro <!b [f]
   (if
      (some nil? [(resolve 'vertx-bus-routes) (resolve 'solved-vertx-routes)])
      (println "need use require-vertx function first")

      (let [function-name (first f)
            arguments     (rest f)]
         (if-let [function-route (get @solved-vertx-routes function-name 
false)]    ;;if the route address was indexed
            (send function-route arguments)                                     
    ;;only send the message using this address
            (go
               (let [full-names       (map #(str % ":" function-name) 
@vertx-bus-routes)  ;;1)concatenate the name with the full address list
                     response-channel (chan (count @vertx-bus-routes))          
          ;;2)create a channell
                     [correct-route res] (loop []                               
          ;;4) take only the address where you get a non false response
                                            (let [res (<! response-channel)]
                                               (if (not (false? res))
                                                  res
                                                  (recur))))]
                  (do
                     (doseq [name full-names] (test-bus name arguments 
response-channel))   ;;3) take the address list and send a message to every 
address
                     (assoc @solved-vertx-routes function-name correct-route)   
            ;;5) store the correct address in a map function-name -> correct 
address
                     res)))))))



I add this to gist https://gist.github.com/anonymous/9fc79679e17e36c47994


when I try run it I get: CompilerException java.lang.IllegalArgumentException: 
Unable to resolve classname: LinkedList


I did a simplified version of the code (also uploaded to gist line 25)..I move 
the correct response outside the let thinking than maybe could be the 
problem...but this fails


(def data (atom ""))
(defmacro blahhh []
   (go
      (let [ch (chan)]
         (do
            (loop []
               (let [res (<! ch)]
                  (if (= res "secret")
                     (do (println ">>" res)
                         (reset! data res))
                     (recur))))
            (doseq [word ["blah" "bang" "secret" "goal"]] (put! ch word))))))


I've three questions:

1) why the exception

2) is correct use a macro?..I'm using a macro because I need avoid try evaluate 
the function in the argument and instead I use it as data..but the code results 
a bit weird because I'm not generating code..I though than I need quote the 
full macro body but I read this article


http://www.braveclojure.com/writing-macros/


and He did something similar

(defmacro postfix-notation
  [expression]
  (conj (butlast expression) (last expression)))
(macroexpand '(postfix-notation (1 1 +))); => (+ 1 1)


One key difference between functions and macros is that function arguments are 
fully evaluated before they're passed to the function, whereas macros receive 
arguments as unevaluated data structures.


3) Any better way of do it?...suggestion?..the way how I use the channel is not 
elegant neither...


thanks so much guys!

2


-- 
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/d/optout.

Reply via email to