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
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
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
I tried this and it works, but I need 2 backticks and I'm essentially
generating the assert-form when the macro is called...I'd like to
generate only the def-form at run-time...
(defmacro defcomponent [name co]
`(assert (component? ~co) Not a valid IComponent)
`(def ~name ~co))
it looks
= (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
that one doesn't actually work, maybe, not sure why exactly but the assert
is ignored
= (def component? number?)
#'runtime.q/component?
= (defmacro defcomponent [name co]
`(assert (component? ~co) Not a valid IComponent)
`(def ~name ~co))
#'runtime.q/defcomponent
= (defcomponent a a)
aaa I see! How can I be so naive some times? ;)
Jim
On 21/02/13 14:15, AtKaaZ wrote:
= (def component? number?)
#'runtime.q/component?
= (defmacro defcomponent [name co]
`(do
(assert (component? ~co) Not a valid IComponent)
(def ~name ~co)
)
)
I settled for:
(defmacro defcomponent [name co]
`(let [c# ~co]
(assert (component? c# Not a valid IComponent))
(def ~name c#)))
Jim
On 21/02/13 14:18, AtKaaZ wrote:
that one doesn't actually work, maybe, not sure why exactly but the
assert is ignored
= (def component? number?)
that's much better, evaluated only once, thanks.
On Thu, Feb 21, 2013 at 3:20 PM, Jim foo.bar jimpil1...@gmail.com wrote:
I settled for:
(defmacro defcomponent [name co]
`(let [c# ~co]
(assert (component? c# Not a valid IComponent))
(def ~name c#)))
Jim
On 21/02/13 14:18, AtKaaZ
oops major typo! the correct is:
(defmacro defcomponent [name co]
`(let [c# ~co]
(assert (component? c#) Not a valid IComponent)
(def ~name c#)))
However, this doesn't work! Something weird with the assertion...If I
comment it out it works as expected, otherwise the var is unbound at the
(defmacro defcomponent
[name co]
`(do
(def ~name ~co)
(set-validator! (var ~name) component?)))
Maybe like this? (Untested)
Kind regards
Meikel
--
--
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to
with eval it may not work as you expected + the double evaluation
(def component? nil?)
= (defmacro defcomponent [name co]
(assert (component? (eval co)) Not a valid IComponent)
`(def ~name ~co)
)
#'runtime.q/defcomponent
= (defcomponent a (println a))
a
a
#'runtime.q/a
= (let [aa
I think the assert is working but either something eats up the thrown
exception silently which would explain why def isn't reached, OR the
defcomponent is never called, OR it is called with a different name param
as you'd have expected. Try putting something before the assert to log if
that point
Hi Meikel,
This seems to work but returns nil and so you can't see that a new var
has been defined!
cluja.core= (defcomponent maxent-person maxent)
nil
cluja.core= maxent-person ;;was it defined?
#NameFinderME opennlp.tools.namefind.NameFinderME@2019666a ;;yes it was!
Jim
On 21/02/13
Then simply add a (var ~name) as last statement in the do.
Kind regards
Meikel
--
--
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
Yes you're right, this does the trick...However now I've ended up
unquoting 'name' 3 times! I'm pretty sure this not a good practice in
general, is it? On the other hand I cannot use 'gensym' cos I want the
name intact or later access...hmmm...I never expected this would be so
confusing!
Jim
Moreover, now the exception thrown when the validation fails is not very
informative!
IllegalStateException Invalid reference state clojure.lang.ARef.validate
(ARef.java:33)
assert let's you speciy the message you want that is why I preferred it...
Jim
On 21/02/13 14:56, Jim foo.bar
this is what i'd use
(def component? number?)
*(defmacro defcomponent [name co]
`(let [c# ~co]
(assert (component? c#)
(str Not a valid IComponent passed:\nevaluated form: `
(pr-str c#) `\noriginal form: `
'~co `\nfull form: ` '~form `
\nlocation: ~(meta
I apologise...this works almost perfectly:
(defmacro defcomponent [name co]
`(let [c# ~co]
(assert (component? c#) Not a valid IComponent)
(def ~name c#)))
the only slight problem is the error thrown which has the gensym symbol
in the flailing condition...Well, I can't have everything can
Hi,
Am Donnerstag, 21. Februar 2013 16:08:36 UTC+1 schrieb Jim foo.bar:
I apologise...this works almost perfectly:
(defmacro defcomponent [name co]
`(let [c# ~co]
(assert (component? c#) Not a valid IComponent)
(def ~name c#)))
the only slight problem is the error thrown which has
I'd actually use this myself:
;the following is inspired from
http://blog.jayfields.com/2011/02/clojure-and.html
(defmacro get-lexical-env []
= (let [a 1 b (+ 1 2)]
(let [c (do \a\ \b\)]
(q/get-lexical-env)
)
)
{a 1, b 3, c \b\}
(let [envkeys (keys env)]
`(zipmap
21 matches
Mail list logo