=> (def component? number?) #'runtime.q/component? => (defmacro defcomponent [name co] `(do (assert (component? ~co) "Not a valid IComponent") (def ~name ~co) ) ) #'runtime.q/defcomponent
=> (defcomponent a (str "a")) AssertionError Assert failed: Not a valid IComponent (runtime.q/component? (str "a")) runtime.q/eval6570 (NO_SOURCE_FILE:1) => (defcomponent a "a") AssertionError Assert failed: Not a valid IComponent (runtime.q/component? "a") runtime.q/eval6572 (NO_SOURCE_FILE:1) => (defcomponent a 1) #'runtime.q/a => (defcomponent a (+ 1 3)) #'runtime.q/a On Thu, Feb 21, 2013 at 3:11 PM, AtKaaZ <atk...@gmail.com> wrote: > or you could place the assert inside the backquote > > > On Thu, Feb 21, 2013 at 3:10 PM, Jim foo.bar <jimpil1...@gmail.com> wrote: > >> On 21/02/13 14:07, Jim foo.bar wrote: >> >>> Hi all, >>> >>> I''d like to have a macro like the following but preferably without the >>> 'eval' inside the assertion form: >>> >>> (defmacro defcomponent [name co] >>> (assert (component? (eval co)) "Not a valid IComponent") >>> `(def ~name ~co)) >>> >>> If I don't use eval, everything works as long as I pass a var >>> in...However if I pass in something like (String. "jam") it is not being >>> evaluated and thus is a list not an object...and it will never satisfy >>> IComponent. >>> >>> any thoughts? >>> thanks in advance :) >>> >>> Jim >>> >>> >>> >> I could have phrased this better...One of my arguments has to NOT be >> evaluated (name) but the other needs to be evaluated (co) so I can assert >> whatever I want to assert on it...I cannot use 'defn' (it will cause 'name' >> to be evaluated) so my only option is a macro that forces eval on the >> second arg, yes? >> >> >> Jim >> >> -- >> -- >> 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+unsubscribe@**googlegroups.com<clojure%2bunsubscr...@googlegroups.com> >> For more options, visit this group at >> http://groups.google.com/**group/clojure?hl=en<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+unsubscribe@**googlegroups.com<clojure%2bunsubscr...@googlegroups.com> >> . >> For more options, visit >> https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out> >> . >> >> >> > > > -- > Please correct me if I'm wrong or incomplete, > even if you think I'll subconsciously hate it. > > -- Please correct me if I'm wrong or incomplete, even if you think I'll subconsciously hate it. -- -- 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.