On Fri, Jun 7, 2013 at 12:30 PM, David Pollak <feeder.of.the.be...@gmail.com
> wrote:

>
>
>
> On Fri, Jun 7, 2013 at 11:14 AM, Ben Wolfson <wolf...@gmail.com> wrote:
>
>>
>>
>> The macro (which IMO is terrible and shouldn't be emulated)
>>
>
> Why do you think the macro is terrible?
>

It's unnecessarily unhygienic:

user> (require '[clojure.core.match :refer [match]])
nil
user> (defmacro match-func [& body] `(fn [~'x] (match [~'x] ~@body)))
#'user/match-func
user> ((match-func [s] x) 1)
1
user> ((match-func [[q s]] [q s]) [1 2])
[1 2]
user> ((match-func [[q x]] [q x]) [1 2])
nil
user>

Proper use requires knowing how it's implemented, and its error messages
are opaque:

user> (match-func [a s] s)
CompilerException java.lang.AssertionError: Pattern row 1: Pattern row has
differing number of patterns. [a s] has 2 pattern/s, expecting 1 for
occurrences [x], compiling:(NO_SOURCE_PATH:1)

It wouldn't be hard to catch that error and alert the user before passing
it on to core.match/match. (Though, to be fair, lots of clojure macros seem
to take the view that enforcement of proper syntax is someone else's
problem.)

(I also favor More Parens for grouping purposes; I think it's ugly and hard
to read when you write (match-func pattern1 action1 pattern2 action2) and
have them all mixed up together like that. But that also applies to
core.match itself, so. I will say that insofar as this is a macro for
defining functions, it would be better if the actions to be taken on
successful matches were wrapped in implicit dos, which is something that's
only possible if the pattern row/action pairs are themselves delimited by
parens or something paren-like.)

-- 
Ben Wolfson
"Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure."
[Larousse, "Drink" entry]

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