Hi, I've been having a great time using Clojure in the last few month.
But this week I've come accross something that is blocking me. I'm
trying to write a very simple pattern matching macro to use in other
macros for matching forms. I've based my macro on one posted in this
group by James Reeves a few months ago. It's working great but, as it
uses eval, it does not evaluate in the lexical scope.

(defmacro match [value & clauses]
  (when (and clauses (= 0 (rem (count clauses) 2)))
    (let [m (gensym 'm)]
      `(if-let ~m (match-forms '~(first clauses) ~value)
         (eval (list 'let ~m '~(second clauses)))
         (match ~value ~@(rrest clauses))))))

user=> (match '(1 2 3) (a b c) (list c b a))
(3 2 1)
user=> (let [z 4] (match '(1 2 3) (a b c) (list z c b a)))
java.lang.Exception: Unable to resolve symbol: z in this context

How can I get around this problem? I'm personnaly not very fond of
using eval so is there another special form better suited for this? Or
maybe it would be better to find another way to resolve this problem,
but I can't think of anything right now.

Thanks
--~--~---------~--~----~------------~-------~--~----~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to