Sorry this is too much information and too much context for what might be subtle bug.
Please demonstrate what you consider to be issues one by one minimally with ClojureScript only. Many thanks, David On Wed, Feb 18, 2015 at 9:04 AM, Ivan Mikushin <[email protected]> wrote: > Hi, > > I'm porting expectations (https://github.com/jaycfields/expectations) to > ClojureScript and may have encountered a compiler bug along the way. An > expectations test looks like this: > > (expect expected actual), > > where expect is a macro that produces a def with a generated symbol as its > name. > > When a macro generates a def and its name contains a generated symbol, the > corresponding var wouldn't contain all metadata and would deref to nil > (weirdly, it'd still have some of the properties like :file and :line). > See the minimal case here: https://github.com/imikushin/metabug > > > Consider the following macros: > > (defmacro assume-named [name a] > (assert (symbol? name) (str name)) > `(def ~(vary-meta name assoc :test `(with-meta (fn []) {:assumption > true})) > (fn [] (assert ~a (str '~a " => " ~a))))) > > (defmacro assume [a] > `(assume-named ~(gensym "assume") ~a)) > > > If we try to obtain a collection of vars for a namespace, containing > applications of assume, like > > (assume (= 3 (+ 1 2))) > > we'd get vars that would deref to nil and would have metadata looking like > something like this: > > {:arglists (), :test nil, :name assume5369, :column 1, :line 4, :file > /home/ivan/src/clojure/metabug/test/metabug/gen_test.cljs, :doc nil, :ns > metabug.gen-test} > > > But, if we use assume-named, like this > > (assume-named test-numbers-equal (= 3 (+ 1 2))) > > we'd get a var with (something like) the following metadata: > > {:arglists (), :test #<[object Object]>, :name test-numbers-equal, > :column 1, :line 4, :file > /home/ivan/src/clojure/metabug/test/metabug/named_test.cljs, :doc nil, :ns > metabug.named-test} > > If we further inspect it with (some-> the-var meta :test meta), we'd get > what's expected to be there: {:assumption true}. > > BTW, it doesn't matter if the generated name is (gensym "prefix") or > something like (symbol (str "prefix" (swap! my-counter* inc))). > > > If, instead, we use names composed entirely of static strings or symbols > from the source file, the metadata is preserved and the vars get deref'ed > correctly. E.g. the following macro produces "good" vars: > > (defmacro assume-prefix-named [name a] > (assert (symbol? name) (str name)) > `(assume-named ~(symbol (str "prefix-" name)) ~a)) > > -- > Note that posts from new members are moderated - please be patient with > your first post. > --- > You received this message because you are subscribed to the Google Groups > "ClojureScript" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/clojurescript. > -- Note that posts from new members are moderated - please be patient with your first post. --- You received this message because you are subscribed to the Google Groups "ClojureScript" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/clojurescript.
