samppi a écrit : > Thanks for the reply. I've tried delays, but it seemed to make my > functions much slower. I think I'm going to go with var-quoting—it > seems to be the least intrusive option, and it definitely works. My > nightmare is finally over. :) > > I wonder if there's a way to make a macro make even this unneeded for > the end-user, though. >
Yup, elaborating on my third option: (defn conc* [tokens & subrules] (loop [subrule-queue (seq subrules), remaining-tokens (seq tokens), products []] (if (nil? subrule-queue) [products remaining-tokens] (let [[subrule-products subrule-remainder :as subrule-result] ((first subrule-queue) remaining-tokens)] (when-not (nil? subrule-result) (recur (rest subrule-queue) subrule-remainder (conj products subrule-products))))))) (defn alt* [tokens & subrules] (some #(% tokens) subrules)) (defmacro conc [& subrules] `(fn [tokens#] (conc* tokens# ~...@subrules))) (defmacro alt [& subrules] `(fn [tokens#] (alt* tokens# ~...@subrules))) (declare value) (def array (conc array-start value array-sep value array-end)) (def value (alt array bit)) Christophe --~--~---------~--~----~------------~-------~--~----~ 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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---