(quote foo) should be interpreted as a literal match. I thought this was
addressed by a previous user submitted patch but it doesn't look like
that's true.

We currently use seqs as a marker of custom syntax, we dispatch either on
the first or second element of the seq. For example this is how we handle
or:

(defmethod emit-pattern-for-syntax [:or Object]
  [pat] (or-pattern
         (->> pat
              (map emit-pattern)
              (into []))))

So you need to add a new case - [quote Object], and emit a literal pattern.
Feel free to open a ticket in JIRA. Patch welcome!

David

On Wed, Nov 30, 2011 at 2:49 PM, Alex Miller <a...@puredanger.com> wrote:

> I've been working with core.match some this week and finding it pretty
> nice.  However, I have a common case (for me) that is not well handled
> right now via core.match: matching symbols. Say that I wrote a match
> like this:
>
> ;; translate (+ x (+ y z)) to (+ x y z)
> (let [e '(+ 1 (+ 2 3))]
>  (match [e]
>       [([+ x ([+ y z] :seq)] :seq)] (+ x y z)))
>
> You will see this error:
> Pattern row 1: Pattern row reuses wildcards in [([+ x ([+ y
> z] :seq)] :seq)].  The following wildcards are ambiguous: +.  There's
> no guarantee that the matched values will be same.  Rename the
> occurrences uniquely.
>
> Any symbol inside a pattern row is treated as a bind variable.  + is a
> symbol.  You can achieve this with guards:
>
> (defn +? [s] (= '+ s))
>
> (let [e '(+ 1 (+ 2 3))]
>  (match ['(+ 1 (+ 2 3))]
>       [([(_o1 :when +?) x ([(_o2 :when +?) y z] :seq)] :seq)] (list
> '+ x y z)))
>
> but, yuck.  I can imagine using the reserved ()'s with additional keys
> (:symbol or :sym) to do symbol matching like (:symbol +) but also,
> yuck.  The simplest idea I came up with was:
>
> (let [e '(+ 1 (+ 2 3))]
>  (match [e]
>       [(['+ x (['+ y z] :seq)] :seq)] ('+ x y z)))
>
> These come through as (quote x) although the error reporting goes a
> little off the rails:
> Pattern row 1: Pattern row reuses wildcards in [([(quote +) x ([(quote
> +) y z] :seq)] :seq)].  The following wildcards are ambiguous: quote.
> There's no guarantee that the matched values will be same.  Rename the
> occurrences uniquely.
>
> However, that seems fixable and you could then use (quote x) as a
> signal to do symbol matching.  If I can figure out what the hell I'm
> doing in core.match then I'd be happy to work on a patch.
>
> Thoughts?
>
> --
> 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 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