On Mon, Oct 10, 2011 at 2:43 PM, Steve Miner <stevemi...@gmail.com> wrote:

> I've just been playing around a bit with match so please forgive me if I've
> missed some prior discussions regarding issues that are considered settled.
>
> One of my first attempts was to match a vector of two of the same thing
> using a pattern like [a a].  I naively thought that would imply an equality
> constraint between the two items, but in fact each variable matched anything
> independently. I now understand that the pattern variables are considered in
> different scopes, but I think it's confusing.  It's reasonable that you want
> something faster than unification for simple literal patterns, but this to
> my mind is a special case that's likely to trip people up.
>

I would accept a patch that would make equality constraints work. We would
have to track "named wildcards" and if they are reused, impose the
constraint.


> In any case, if using multiple pattern variables of the same name does not
> imply an equality constraint, I suggest that it be considered an error to
> reuse a pattern variable.  It's better to throw than to yield an unexpected
> match.
>

In the meantime throwing an error if names are reused in a pattern row is a
good idea. http://dev.clojure.org/jira/browse/MATCH-30


> Regarding OR patterns, I didn't really like the infix notation, (1 | 2).
>  As a lisper, I'd prefer to use something like (or 1 2), or maybe even a
> Clojure set notation: #{1 2}. I'm guessing you already thought about this
> and made your decision on syntax, but I thought I'd throw it out there.
>

Set notation doesn't communicate that order is important. (or 1 2) overloads
the meaning of the or construct. I'm not sold on the infix notation either.
Looking for more feedback / ideas on this.


> For guards, I wonder if the extra parens are really necessary.  Couldn't
> the :when bind tightly to the previous pattern variable?  Like Clojure FOR
> comprehensions.  I think it would be easier to read that way.  Same comment
> applies to :as.  To cover the rare case of matching a literal :when or :as,
> you could quote it or use it as the first item in an OR pattern.
>

It would be nice to lose the extra parens - patch welcome :)


> As others have suggested, I agree that returning nil when nothing matches
> makes sense.  That was my original expectation.
>
> It was common when testing to wrap a let around the match so I made a
> little macro to save a few characters.  Free for anyone who wants it.  :-)
>
> (defmacro match-let [bindings & body]
>  (let [bindvars# (take-nth 2 bindings)]
>    `(let ~bindings
>       (match [~@bindvars#]
>                ~@body))))
>
>
> Steve Miner
> stevemi...@gmail.com


match-let looks good. I see that you are Clojure contributor - I'm more than
happy to include this.

Steve, this is great feedback - much appreciated.

David

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