There's no way to make that work currently. Whether it should work requires
some discussion but at the moment I'm inclined to say no.

On Wednesday, November 14, 2012, David Jagoe wrote:

> Hi all,
>
> I have a core.match pattern that looks something like this:
>
> (def !nil? (complement nil?))
>
> (match [*a* *b*]
>     [(a :guard !nil?) nil] (dosomething a)
>     [nil (b :guard !nil?)] (dosomething b)
>     [(a :guard !nil?) (b :guard !nil?)] (dosomething a b)
>     :else (throw (Exception. "Not allowed"))
>
> The point is that in every case I guard the variable using !nil?
>
> I would like to shorten my code:
>
> (match [*a* *b*]
>     [(!nil a) nil] (dosomething a)
>     [nil (!nil b)] (dosomething b)
>     [(!nil a) (!nil b) (dosomething a b)
>     :else (throw (Exception. "Not allowed"))
>
> But I can't figure out how to write the !nil macro.
>
> I've tried:
>
> (defmacro notnil [sym]
>     `(~sym :guard (complement nil?)))
>
> Which looks right in expansion:
>
> (macroexpand-1 '(!nil foo))
> -> (foo :guard (clojure.core/complement clojure.core/nil?))
>
> But I cannot use this in a match:
>
> (let [foo nil bar 2]
>                             (match [foo bar]
>                                    [(!nil foo) 2] foo
>                                    :else :notfound))
> CompilerException java.lang.AssertionError: Invalid list syntax foo in
> (!nil foo)
>
> Why!!?!??!
>
> I guess its got something to do with the fact that match itself is a macro?
>
> Is there some other way that I could extend match to only match when the
> variable is not nil?
>
> Thanks,
> David
>
>
>
> --
> David Jagoe
>
> davidja...@gmail.com <javascript:_e({}, 'cvml', 'davidja...@gmail.com');>
> +18053284389
>
> --
> 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<javascript:_e({}, 'cvml', 
> '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 <javascript:_e({}, 'cvml',
> 'clojure%2bunsubscr...@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 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

Reply via email to