On Sun, Aug 24, 2008 at 12:46 PM, budu <[EMAIL PROTECTED]> wrote: > > 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)
I believe you're referring to this: http://groups.google.com/group/clojure/browse_thread/thread/c6db9116197420c8/e40a1ae84887622d However, you've made some changes -- your match macro above is different from James Reeves', and simply renaming "matches?" to "match-forms" still doesn't allow your example to work. This makes it difficult to help you! Would you mind posting a working example? So it's hard to be sure, but I suspect we'll be able to find a solution. I think this because the eval in match is executed at runtime, not when the macro is evaluated. This means I think we ought to be able to make the match macro emit the appropriate code to have the same behavior as the eval, but without any eval at all. --Chouser --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] 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 -~----------~----~----~----~------~----~------~--~---
