Fork me on GitHub
#beginners
<
2017-01-10
>
roelof08:01:24

Someone a idea when I use atom and I have some spec tests in my code. The proto-repl refuses to boot up properly

roelof08:01:46

I have disabled all the refresh parts in the settings of proto-repl

agile_geek09:01:09

@roelofw you could ask in the #protorepl channel and see if someone there can help.

wilcov13:01:37

This has probably been asked alot of times but is it true that the symmetrize-body-parts function of clojure for the brave and true is flawed? the loop creates an empty remaining-asym-parts let and then checks if it's empty..

agile_geek13:01:52

@wilcov does it? Where are you getting the code from? I don't have a print version but this is from the on-line version:

(defn symmetrize-body-parts
  "Expects a seq of maps that have a :name and :size"
  [asym-body-parts]
  (loop [remaining-asym-parts asym-body-parts
         final-body-parts []]
    (if (empty? remaining-asym-parts)
      final-body-parts
      (let [[part & remaining] remaining-asym-parts]
        (recur remaining
               (into final-body-parts
                     (set [part (matching-part part)])))))))
This code sets remaining-asym-parts to the asym-body-parts argument passed to the fn. Can't see anything wrong there?

wilcov13:01:28

that's weird, i also got the code form the online version. The result i get is

[{:name "head", :size 3} {:name "left-eye", :size 1} {:name "left-ear", :size 1} {:name "mouth", :size 1} {:name "nose", :size 1} {:name "neck", :size 2} {:name "left-shoulder", :size 3} {:name "left-upper-arm", :size 3} {:name "chest", :size 10} {:name "back", :size 10} {:name "left-forearm", :size 3} {:name "abdomen", :size 6} {:name "left-kidney", :size 1} {:name "left-hand", :size 2} {:name "left-knee", :size 2} {:name "left-thigh", :size 4} {:name "left-lower-leg", :size 3} {:name "left-achilles", :size 1} {:name "left-foot", :size 2}]

wilcov13:01:55

So it just spits back the original values

wilcov13:01:25

So my original statement was false, it doesn't set it to an empty value (wrong logic on my part). But it also doesn't add the right-side body parts. which is what confused me originally

wilcov13:01:37

the matching-part function is also taken from the website

agile_geek13:01:23

Not what I get. Are you sure you eval'ed all the fn's and def's and that your repl is in the correct state?

agile_geek13:01:42

I get this:

[{:name "head", :size 3}
 {:name "left-eye", :size 1}
 {:name "right-eye", :size 1}
 {:name "left-ear", :size 1}
 {:name "right-ear", :size 1}
 {:name "mouth", :size 1}
 {:name "nose", :size 1}
 {:name "neck", :size 2}
 {:name "left-shoulder", :size 3}
 {:name "right-shoulder", :size 3}
 {:name "right-upper-arm", :size 3}
 {:name "left-upper-arm", :size 3}
 {:name "chest", :size 10}
 {:name "back", :size 10}
 {:name "left-forearm", :size 3}
 {:name "right-forearm", :size 3}
 {:name "abdomen", :size 6}
 {:name "left-kidney", :size 1}
 {:name "right-kidney", :size 1}
 {:name "left-hand", :size 2}
 {:name "right-hand", :size 2}
 {:name "right-knee", :size 2}
 {:name "left-knee", :size 2}
 {:name "right-thigh", :size 4}
 {:name "left-thigh", :size 4}
 {:name "right-lower-leg", :size 3}
 {:name "left-lower-leg", :size 3}
 {:name "right-achilles", :size 1}
 {:name "left-achilles", :size 1}
 {:name "right-foot", :size 2}
 {:name "left-foot", :size 2}]

agile_geek13:01:10

@wilcov silly question but you are invoking symmeterize-body-parts correctly? I.e. (symmetrize-body-parts asym-hobbit-body-parts) and not symmetrize-body-parts asym-hobbit-body-parts? The second one is without the parens and will just return the eval'ed symbol asym-hobbit-body-parts which will obviously just be the initial value.

wilcov13:01:13

@agile_geek yes i was using the parentizes version. I've loaded up a lein repl (i use spacemacs with the clojure layer normally) and after i manually define the functions and values i get the correct values. Thanks for your help, it seems there's either something wrong with my spacemacs or i'm simply not using it right

agile_geek14:01:54

I use emacs rather than spacemacs but the only real difference is the keybindings and it works in eamcs. Make sure you eval the whole buffer with your code in it using CIDER (in emacs this is normally bound to C-c C-k not sure in spacemacs)

wilcov14:01:00

@agile_geek i created a new file and copied the functions. The new file works so there was a error somewhere in the old file. I have no idea where, defining the functions never gave an error but oh well. Thanks 🙂 i can continue my learning journey haha, was stuck for several hours

roelof14:01:00

If I do this :

(get-data-front-page(get-art-object(read-json-data "SK-C-5")))  

roelof14:01:23

then the outcome is this :

{:name "Rembrandt Harmensz. van Rijn", 
 :title "Schutters van wijk II onder leiding van kapitein Frans Banninck Cocq, bekend als de ‘Nachtwacht’", 
 :id "SK-C-5"}  

roelof14:01:28

which is good

roelof14:01:04

but when I try to do the same with :

(pmap (comp get-data-front-page get-art-object read-json-data) "SK-C-5") 

roelof14:01:29

I see this output :

Exception Something wrong with the front-pag e  paintings2.api-get/get-data-front-page  

roelof14:01:44

Can someone explain to me why this happens ?

schmee14:01:22

pmap applies the function to a sequence

schmee14:01:43

so in your example it will convert the string into a seq of chars and use the function on each char separately

schmee14:01:10

to make it work the same way, wrap the string in a vec: (pmap (comp get-data-front-page get-art-object read-json-data) [”SK-C-5"])

roelof15:01:49

@schmee : you are right

roelof15:01:11

I have another test question

roelof15:01:20

When I do this :

(defn test-funct
 "all the test"
 []
 (stest/summarize-results (stest/check 'paintings2.api-get/get-objectNumbers))
 (stest/summarize-results (stest/check 'paintings2.api-get/get-art-object))
 (stest/summarize-results (stest/check 'paintings2.api-get/get-data-detail-page))
 (stest/summarize-results (stest/check 'paintings2.api-get/get-data-front-page))
 (stest/summarize-results (stest/check `paintings2.api-get/get-image-url))
 (stest/summarize-results (stest/check `paintings2.api-get/get-data-front-page-url))
 (stest/summarize-results (stest/check `paintings2.api-get/get-data-detail-page))) 

roelof15:01:27

all test are successfull

roelof15:01:12

now someone in the proto-repl says I could replace my function with this :

(defn test-funct
 "all the test"
 []
 (stest/summarize-results (stest/check)))  

roelof15:01:14

now the front-page and detail page test are failing like this:

{:sym paintings2.api-get/get-data-front-page}
{:spec
 (fspec
  :args
  (cat :args (coll-of :paintings2.api-get/objectNumber))
  :ret
  (coll-of (and :basic/artObject :image/object))
  :fn
  nil),
 :sym paintings2.api-get/fetch-paintings-and-images-front-page,
 :failure #error {
 :cause "Something wrong with the front-pag e"
 :via
 [{:type java.util.concurrent.ExecutionException
   :message "java.lang.Exception: Something wrong with the front-pag e"
   :at [java.util.concurrent.FutureTask report "FutureTask.java" 122]}
  {:type java.lang.Exception
   :message "Something wrong with the front-pag e"
   :at [paintings2.api_get$get_data_front_page invokeStatic "form-init1214856096370173557.clj" 147]}]
 :trace
 [[paintings2.api_get$get_data_front_page invokeStatic "form-init1214856096370173557.clj" 147]
  [paintings2.api_get$get_data_front_page invoke "form-init1214856096370173557.clj" 137]
  [clojure.core$comp$fn__6823 invoke "core.clj" 2542]
  [clojure.core$comp$fn__6823 invoke "core.clj" 2542]
  [clojure.core$pmap$fn__9385$fn__9386 invoke "core.clj" 6897]
  [clojure.core$binding_conveyor_fn$fn__6772 invoke "core.clj" 2020]
  [clojure.lang.AFn call "AFn.java" 18]
  [java.util.concurrent.FutureTask run "FutureTask.java" 262]
  [java.util.concurrent.ThreadPoolExecutor runWorker "ThreadPoolExecutor.java" 1145]
  [java.util.concurrent.ThreadPoolExecutor$Worker run "ThreadPoolExecutor.java" 615]
  [java.lang.Thread run "Thread.java" 745]]}} 

roelof15:01:31

Is there a explanation why this happens

roelof15:01:15

it looks like the input is malformed when I do the short syntax of (stest/check)

schmee15:01:04

do you use any mutable objects or something that may not be thread-safe in your functions?

roelof15:01:38

Not that I know of , here is the code when the tests are failing : https://github.com/rwobben/paintings/blob/master/src/clj/paintings2/api_get.clj

schmee15:01:12

does it work if you use map instead of pmap?

roelof15:01:50

nope, then I see the same error

schmee15:01:49

okay, after glancing at the code I couldn’t see anything obvious, so I can’t really help with this one, sorry 😕

manutter5115:01:45

@roelof I have roughly zero experience with clojure.spec.test, so I have no idea what would happen, but I’d be tempted to add a line like _ (prn {:art-object art-object}) just before the line that says checked (s/conform ::artObject art-object) in the get-data-front-page fn

roelof15:01:20

oke, so I can look if there is a difference in the output

roelof15:01:30

is that the purpose ?

roelof15:01:37

@manutter51 when I do that atom seems to not to be responding to anything

manutter5115:01:22

Not sure what you mean by “not responding”? You mean returning nil?

roelof15:01:50

no, I see a message that atom seems not to be responding on my screen

roelof15:01:02

and I do not see anything happing

manutter5115:01:21

Wow, that’s a new one on me

roelof15:01:29

but looking at the output I see I do not see any difference in output of the tests

roelof15:01:15

so the input of the long test seems to be the same if I do only (stest check)

manutter5116:01:26

wait “atom” as in a Clojure (atom), or “atom” as in the Atom editor?

roelof16:01:31

I was talking about the Atom editor

manutter5116:01:11

Whew, my brain was exploding trying to figure out how a Clojure (atom) could fail to respond.

manutter5116:01:07

So art-object is probably too big to render in the repl

manutter5116:01:00

maybe try changing that (prn) line to be _ (prn {:type (type art-object)}) — mostly curious to see if you’re getting some kind of weird data there

roelof16:01:51

Same happens, I see the output od the (-(prn .... )) and then the Atom ide seems not be to responding

jswart17:01:54

The first thing you need to do is confirm that (stest/summarize-results (stest/check)) actually does what you expect.

jswart17:01:20

I would try loading a regular repl from the terminal and running that and seeing if it matches your expectations

jswart17:01:22

if it does

jswart17:01:32

then there is something wrong in your editor, repl, etc.

roelof18:01:27

@jswart im running it from, proto-repl , is that not a regular repl ?

roelof18:01:15

All the test is running in proto-repl

manutter5118:01:30

You could try lein repl to get the old tried-and-true command line repl (or better yet, rlwrap lein repl if you have rlwrap installed)

roelof18:01:06

oke, and I have then to copy the whole file into the repl ?

roelof18:01:14

or can I load it ?

jswart19:01:52

in the project directory

jswart19:01:56

do lein repl

jswart19:01:59

the require your namespace

jswart19:01:22

(require '[my.namespace :as m]) then run your test (m/mytest)

jswart19:01:28

those are made up names

jswart19:01:31

you need to replace them

jswart19:01:51

the problem with things like proto-repl is they are another layer of stuff, and can make things more complicated

jswart19:01:59

better to rule it out early

jswart19:01:26

not a slight, just my experience

roelof19:01:56

This is the output I see (require `[paintings2.api-get :as m]) nil user=> (m/test-funct) CompilerException java.lang.RuntimeException: No such namespace: m, compiling:(C:\Users\rwobb\AppData\Local\Temp\form-init6650075369155190938.clj:1:1)

jswart19:01:39

that is odd

roelof19:01:59

yep, that is why I mentioned it here

jswart19:01:49

can you do (m/ and then press tab and get autocomplete in your REPL?

roelof19:01:22

nothing happens

manutter5119:01:57

If it’s the command line repl, I don’t think autocomplete works, does it?

jswart19:01:04

it does for me

jswart19:01:10

how about doing: (require '[clojure.string :as s]) then (s/blank? “”)

jswart19:01:14

does that work?

manutter5119:01:12

@roelof are you using backtick or single quote there? It looks like ` instead of ‘ in what you pasted

roelof19:01:08

I use the `

jswart19:01:18

you need to use a single quote

jswart19:01:24

that is very different than a backtick

roelof19:01:08

oke, i see now output

jswart19:01:29

On your original paintings2 test?

roelof19:01:25

yes, at some point this is happening :

{:type clojure.lang.PersistentArrayMap}
{:type clojure.lang.PersistentArrayMap}
{:type clojure.lang.PersistentArrayMap}
{:type clojure.lang.PersistentArrayMap}
{{:type :typenil }nil
}
{:type nil}
{:type nil}
{:type nil}
{:type nil}
{:type nil}
{:type nil} 

roelof19:01:42

so the type changes to nil on the failing test

jswart19:01:52

I don’t know anything about proto-repl, but that seems to be where your issue is

jswart19:01:08

maybe it doesn’t like multiline output?

roelof19:01:28

and on a test that is working fine I see this :

nil
nil
nil
nil
nil
nil
nil
{:sym paintings2.api-get/get-art-object}
{:sym paintings2.api-get/get-data-detail-page}
{:sym paintings2.api-get/get-data-front-page}
{:sym paintings2.api-get/get-image-url}
{:sym paintings2.api-get/get-data-detail-page}
{:total 1, :check-passed 1}  

roelof19:01:04

so the type part is not displayed