Good eye. To your second point, I accidentally copied those namespaces out 
when attempting to "focus" my report of this problem. 

*   [com.samedhi.app.fixture :as f]*
*   [clojure.data.generators :as g]*

So clojure.test.generative as generative and clojure.data.generators as g. 

To your last point, yes, using zero? would be more concise and idiomatic.

Finally, to your first point. I don't know why I was using syntax-quotes as 
opposed to regular quotes.

 without quotes or with simple quotes, the namespace evaluates to 
clojure.data.generators (I guess because it is in the tag), the quote 
"hack" is mentioned in the middle of test.generative's github page.
    *[^{:tag random-loc} loc*
*     ^{:tag (clojure.core/constantly :ignored)} key*
*     ^{:tag view} value]*

OR
 
    *[^{:tag 'random-loc} loc*
*     ^{:tag (clojure.core/constantly :ignored)} key*
*     ^{:tag 'view} value]*

=> *java.lang.RuntimeException: No such var: 
clojure.data.generators/random-loc*

With the full expansion, the syntax quote, the quoted full expansion, and 
the syntax-quoted full-expansion, I get the print-dup error:

*    [^{:tag com.samedhi.app.test.behavior-test/random-loc} loc*
*     ^{:tag (clojure.core/constantly :ignored)} key*
*     ^{:tag com.samedhi.app.test.behavior-test/view} value]*

OR

*   [^{:tag `random-loc} loc*
*     ^{:tag (clojure.core/constantly :ignored)} key*
*     ^{:tag `view} value]*

OR 

*  [^{:tag 'com.samedhi.app.test.behavior-test/random-loc} loc*
*     ^{:tag (clojure.core/constantly :ignored)} key*
*     ^{:tag 'com.samedhi.app.test.behavior-test/view} value]*

OR

*  [^{:tag `com.samedhi.app.test.behavior-test/random-loc} loc*
*     ^{:tag (clojure.core/constantly :ignored)} key*
*     ^{:tag `com.samedhi.app.test.behavior-test/view} value]*

=> *Caused by: java.lang.RuntimeException: Can't embed object in code, 
maybe print-dup not defined: Unbound: 
#'com.samedhi.app.test.behavior-test/random-loc*

Finally, with being "commented out" by just returning nil, it does compile 
but of course the actual test fail.

*   [^{:tag (clojure.core/constantly nil)} loc*
*     ^{:tag (clojure.core/constantly :ignored)} key*
*     ^{:tag (clojure.core/constantly nil)} value]*

=> Test fail as they were not expecting nil.

Finally, I thought to just remove the binding in its entirety, setting the 
atom in *view*'s def.

*(def ^:dynamic *view* (atom*
*                  {:old-model [nil nil nil nil nil nil]*
*                   :quiz [nil nil nil nil nil nil nil]*
*                   :loc nil}))*
*
*
*(defn view [] @*view*)*
*
*
*(defn random-loc []*
*  (let [loc (-> (view) :loc random-walk-loc)*
*        loc (if (= 0 (g/uniform 0 100)) (f/loc) loc)]*
*    (swap! *view* assoc :loc loc)*
*    loc))*
*
*
*(generative/defspec*
*  check-on-quiz-view*
*  b/quiz-view*
*  [^{:tag (clojure.core/constantly nil)} loc*
*   ^{:tag (clojure.core/constantly :ignored)} key*
*   ^{:tag (clojure.core/constantly nil)} value])*

This does work, but now I assume the atom is being shared among all 4 
threads, which isn't really what I wanted. Furthermore, without some 
additional synchronization, I am pretty sure that I could have some invalid 
state.

On Friday, September 20, 2013 12:01:41 AM UTC-7, Stephen Cagle wrote:
>
> *
> (ns com.samedhi.app.test.behavior-test
>   (:require
>    [clojure.test.generative :as generative])
>
>   (:use
>    [com.samedhi.quizry.app.test.defspec :only [defspec]]
> ))
>
> *
> *... ommited content ...*
> *
> *
> *(def ^:dynamic *view* nil)*
> *
> *
> *(binding [*view* (atom                                                ;; 
> this is line 69*
> *                  {:old-model [nil nil nil nil nil nil]*
> *                   :quiz [nil nil nil nil nil nil nil]*
> *                   :loc nil})]*
> *  *
> *    (defn view [] @*view*)*
> *  *
> *    (defn random-loc []*
> *      (let [loc (-> (view) :loc random-walk-loc)*
> *            loc (if (= 0 (g/uniform 0 100)) (f/new-loc) loc)]*
> *        (swap! *view* assoc :loc loc)*
> *        loc))*
> *
> *
> *    (generative/defspec*
> *      check-on-quiz-view*
> *      b/quiz-view*
> *      [^{:tag `random-loc} loc*
> *       ^{:tag (clojure.core/constantly :ignored)} key*
> *       ^{:tag `view} value]))*
>
> Gives me the error:
> *Exception in thread "main" java.lang.RuntimeException: Can't embed 
> object in code, maybe print-dup not defined: Unbound: 
> #'com.samedhi.app.test.behavior-test/random-loc, 
> compiling:(com/samedhi/app/test/behavior_test.clj:69:1)
> *
>
> I vaguely understand that this is saying that something in here does not 
> have a print-dup method on it, and as such, cannot be "codified". How do I 
> determine what the problem is? 
>
> You might wonder why I am using a binding anyway? defspec is from 
> test.generative. This defspec is testing b/quiz-view with the supplied 
> argument vector. I have a dependency between the first argument (loc) and 
> the third argument (value), hence the shared atom. Furthermore, I wish each 
> succesive call to b/quiz-view to be a slight modification of the previous 
> value, where the loc has been randomly moved around a bit. Ocasionally (1 
> in a 100), I just create a entirely new loc with f/new-loc. All of this 
> could have been done with a shared atom. However, it seems that 
> test.generative actually uses N-threads, which means I want each thread to 
> have its own atom. Hence, by my reasoning, the use of binding and 
> ^:dynamic. BTW, the tick before random-loc and view allows them to evaluate 
> in the the current namespace, as otherwise they would be evaluated in 
> clojure.core.generators (I don't really understand why).
>  
> https://github.com/clojure/test.generative ;; just for reference
>
> I am obviously wrong in my implementation (it does not compile), I could 
> be wrong in my reasoning as well, but I am most worried about the fact that 
> I have no real idea *what* is not working here. Any help is appreciated.
>

-- 
-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to