core.match gotcha

2013-01-06 Thread Chas Emerick
I've recently started using core.match, which has been quite pleasant and 
successful; thank you to David Nolen, and all others that have contributed.

The only hiccup I've had has been around how core.match incorporates bindings 
from local scope into pattern rows.  A stupid example demonstrating the 
(potential) confusion:

= (match [[:k]]
 [[x]] x)
:k

vs.

= (let [x 12]
 (match [[:k]]
   [[x]] x))
nil

I was assuming that bindings established by the wildcards in pattern rows 
shadowed any other local bindings.  It took me a while to realize that, e.g. in 
the example above, `x` was being interpolated into `[[x]]` to yield a pattern 
row of `[[12]]`.  Now that I know that, all's well; but, it took me perhaps 
longer than it should have to figure it out.

All this is to say, perhaps a relevant note in the (really excellent) overview 
wiki page[1] might be helpful.

Thanks,

- Chas

[1] https://github.com/clojure/core.match/wiki/Overview

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


Re: core.match gotcha

2013-01-06 Thread Chas Emerick

On Jan 6, 2013, at 10:48 AM, Ambrose Bonnaire-Sergeant wrote:

 On a related note, combining a quoted symbol and a named wildcard pattern 
 seems to be buggy.
 
 clojure.core.match= (match 'my-sym a a)
 #CompilerException java.lang.RuntimeException: Unable to resolve symbol: 
 ocr-3612 in this context, compiling:(REPL:79)
 clojure.core.match= (macroexpand-1 '(match 'my-sym a a))
 (clojure.core/let [a ocr-3620] a)

Yeah, I've hit that, but presumed I was just doing something wrong. :-)

 I included a section on how symbols work as patterns.

Perfect, reads very well.  I'm glad I didn't just add something, it would not 
have been as clear or succinct.

 Interestingly, the old design page still has some good stuff, including an 
 explanation of this particular issue.
 I'm not sure how much is still relevant.
 
 https://github.com/clojure/core.match/wiki/Design-Wiki

Ach, I hadn't thought to look at what else might be lurking in the wiki!  The 
'Local Bindings' section on the design page would have made it all obvious.

Thanks!

- Chas

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

Re: core.match gotcha

2013-01-06 Thread Chas Emerick
On Jan 6, 10:48 am, Ambrose Bonnaire-Sergeant
abonnaireserge...@gmail.com wrote:
 On a related note, combining a quoted symbol and a named wildcard pattern
 seems to be buggy.

 clojure.core.match= (match 'my-sym a a)
 #CompilerException java.lang.RuntimeException: Unable to resolve symbol:
 ocr-3612 in this context, compiling:(REPL:79)
 clojure.core.match= (macroexpand-1 '(match 'my-sym a a))
 (clojure.core/let [a ocr-3620] a)

Ticket opened here FWIW:

   http://dev.clojure.org/jira/browse/MATCH-66

- Chas

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