Michael Wood wrote: > > (defn with-test-report [test fn] > > You are shadowing clojure.core/fn here. Not a problem really, but > perhaps it would be better to use a different name? Oh, and > clojure.core/test.
Oh, right! Didn't think of it this way; it might be misleading to any future reader, so I take note. > > (defn with-test-report [test fn] > > (let [assert# (first test) > > expect# (second test) > > params# (last test) > > result# (assert# expect# (apply fn params#))] > I've seen various code snippets where people use something# in > functions. Is there any point to this or gensym except in a macro? In another function, if I didn't gensym my let-bounds, they would interact with an outer lexical context, if I remember well. (Note that my observations at that time could have been totally wrong.) So I figured out that since `let` is a special form, it might have a different behavior than what I'm used to see in Common Lisp. Gensym- ing fixed my issues and since then I always do so for my let-bounds. I also have seen it in other people's code, but I only remember seeing it in `let` expressions (apart from macros, of course). It would great to hear the advice on that matter of someone more knowledgeable than I. > > Exception: Unable to resolve var: expect# in this context > > How about using a macro. e.g.: > > (defmacro with-test-report [tst f] > `(let [pred# (first ~tst) > pname# '~(first tst) > expect# (second ~tst) > params# (last ~tst) > result# (pred# expect# (apply ~f params#))] > (if result# > (print ".") > (do (newline) > (println (format "FAIL: [%s %s]" pname# params#)))) > result#)) > nil > user=> (with-test-report [= 3 [1 3]] +) > > FAIL: [= [1 3]] > false Cool! Even when experimenting with macros, it didn't work for me! Thank you Michael. I still wish I knew how to achieve this without resolving to macros. Macros are what seduced me towards lisp instead of, say, haskell, so my goal in learning any real lisp (Clojure here) is to try as hard as I can to not use macros so that I don't develop a bad habit of writing macros when obvious functions would have done the same job. This way, I'll really appreciate macros for their usefulness without fooling myself. When I'll have developed a good intuition about this, I'll of course loosen that rule. If anyone could chime in and tell me if macros are the only out of this problem, that would be really great. To simplify the problem to its essence, let's say I'd like, without using macros, the following to print better: (print (first [= 1 2])) #<core$_EQ___2886 clojure.core$_eq___2...@830122> Hey, I just found out the following works: (print (first '(=))) = But in my previous (different) attempts, I couldn't make it work. Well, I may have found a good way to refactor out my issue. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---