Fork me on GitHub
#beginners
<
2017-02-07
>
bones00:02:46

I’ve got the cycle sorted, is there a way I can use it with channels, specifically transducers? So that no matter what goes on the channel all i get is an alternating sequence of say, either :a or :b?

clodeindustrie01:02:34

@seancorfield fair enough, I’m not used to that, so it felt massive 😄

alexmiller01:02:04

@bones cycle is not a transducer, but a sequence generator. but you can use to-chan to wrap it into a channel that will produce values forever

eslachance03:02:08

Sigh. Hi there! Me again with a real basic question. How do I add a :require once my repl is already running?

beppu03:02:14

@eslachance (require '[name.space :as alias]) in the repl

eslachance03:02:17

Oh that's simple. thank you!

eslachance03:02:05

Also to answer your question, to-chan creates the channel and inserts a collection into it. onto-chan takes an existing channel and pushes a collection to that existing channel

beppu03:02:24

Yeah, I just read the docs myself. Now I regret deleting the message.

eslachance03:02:28

I do that often to 😛 ¯\(ツ)

roelof06:02:41

I have now this :

(s/def ::description string?) 

roelof06:02:00

how must I change it so :description can be nil ?

akiroz07:02:30

@roelof (s/def ::description #(or (string? %) (nil? %)))

akiroz07:02:26

or if you want to know which one when conformed: (s/def ::description (s/or :string string? :nil nil?))

roelof07:02:05

@akiroz thanks, one problem down on my site

roelof08:02:00

is there another way because when I do

(s/def ::description #(or (string? %) (nil? %))) 

roelof08:02:11

I see a non-gen on that part

akiroz08:02:40

@roelof what about the version with s/or?

roelof08:02:21

im talking about that version. When I do (s/test ... ) I see a non-gen error message

rauh08:02:25

@roelof + CTRL-F + nil 🙂

roelof08:02:15

Now I hope I can find out why this test is failing :

{: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-page"
 :via
 [{:type java.util.concurrent.ExecutionException
   :message "java.lang.Exception: Something wrong with the front-page"
   :at [java.util.concurrent.FutureTask report "FutureTask.java" 122]}
  {:type java.lang.Exception
   :message "Something wrong with the front-page"
   :at [paintings2.api_get$get_data_front_page invokeStatic "form-init240444187305771206.clj" 8]}]
 :trace
 [[paintings2.api_get$get_data_front_page invokeStatic "form-init240444187305771206.clj" 8]
  [paintings2.api_get$get_data_front_page invoke "form-init240444187305771206.clj" 1]
  [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" 266]
  [java.util.concurrent.ThreadPoolExecutor runWorker "ThreadPoolExecutor.java" 1142]
  [java.util.concurrent.ThreadPoolExecutor$Worker run "ThreadPoolExecutor.java" 617]
  [java.lang.Thread run "Thread.java" 745]]}}

roelof08:02:52

pity I cannnot see what data the test function is using

roelof08:02:29

it looks something wrong with the objectNumber as a part of the parameter

roelof09:02:47

very wierd, I changed the objectNumber from a reg-ex to a string and it looks like the old spec is still used

seancorfield09:02:27

@roelof: did you find s/nilable to address your description issue?

sb09:02:23

Do you any idea, how possible to put in every compojure

defroutes
(GET POST PUT) a checking system like whitelist urls or else? I need to drop to “wrap-defaults/site-defaults” part of the code or possible to do in different way? just like (function .. (defroutes..)) what is your experience which is the best? I would like to create custom cookies/session/whitelist system for my code.

sb09:02:09

Ok, I know.. wrap session and assoc-in methods. I use in custom session store.

roelof13:02:13

@seancorfield yes, I do not see any validation issues at that point

roelof13:02:56

Still wierd. When I do the test one for one , I see these results :

(stest/summarize-results (stest/check 'paintings2.api-get/get-data-front-page)) 

{:sym paintings2.api-get/get-data-front-page}
=> {:total 1, :check-passed 1}
+(stest/summarize-results (stest/check 'paintings2.api-get/get-objectNumbers)) 

=> #object[clojure.core$_PLUS_ 0x1d204fe "[email protected]"]
{:sym paintings2.api-get/get-objectNumbers}
=> {:total 1, :check-passed 1}
+(stest/summarize-results (stest/check 'paintings2.api-get/get-art-object)) 

=> #object[clojure.core$_PLUS_ 0x1d204fe "[email protected]"]
{:sym paintings2.api-get/get-art-object}
=> {:total 1, :check-passed 1}
(stest/summarize-results (stest/check 'paintings2.api-get/get-data-detail-page)) 

{:sym paintings2.api-get/get-data-detail-page}
=> {:total 1, :check-passed 1}
(stest/summarize-results (stest/check 'paintings2.api-get/get-data-front-page)) 

{:sym paintings2.api-get/get-data-front-page}
=> {:total 1, :check-passed 1}

roelof14:02:32

Very wierd,. When I do :

(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')))

roelof14:02:40

all tests are green

roelof14:02:15

when I do :

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

roelof14:02:23

two tests are failing

roelof14:02:43

when I delete the summarize part , I see this :

:fail [(["DY-U-2" "OX-M-56" "AI-P-115" "OW-P-2508" "RV-S-925" "EM-N-87" "XJ-D-068"])],`

roelof14:02:27

where objectNumber needs to be a string

roelof14:02:53

and they are all strings

roelof14:02:20

someone a idea why this happens ?

alexmiller15:02:30

@roelof hard to tell without seeing all the code, but that last line you posted has strings in collections 3 levels deep [([ .. ])] - is it possible one or more of those are not needed?

roelof15:02:34

@alexmiller all the code you can find in my github code

roelof15:02:59

and if that is the problem , why does if I do the test alone it is green

alexmiller15:02:51

you might get a better error message if you change the pmap to a map in fetch-paintings-and-images-front-page and fetch-paintings-and-images-detail-page

alexmiller15:02:17

it looks like the error is happening inside those pmapped functions

alexmiller15:02:25

which is obscuring the cause

alexmiller15:02:40

Can you run check on either of those functions and reproduce the problem?

roelof15:02:29

moment, I changed it and change the pmap to a map

roelof15:02:37

I will run the test again

roelof15:02:02

@alexmiller then I see the same error message

roelof15:02:08

only the fail part is missing

alexmiller15:02:38

can you gist the whole thing?

roelof15:02:05

you need a key to make it work but I can give you one in a private chat

alexmiller15:02:27

no, I mean the error message

roelof16:02:19

@alexmiller sorry to response so late,

roelof16:02:00

Here the last error message :

test-funct)
{:sym paintings2.api-get/get-objectNumbers}
{:sym paintings2.api-get/get-data-detail-page}
{:spec
 (fspec
  :args
  (cat :args (coll-of :paintings2.api-get/objectNumber))
  :ret
  (coll-of (and :detail/artObject :image/object))
  :fn
  nil),
 :sym paintings2.api-get/fetch-paintings-and-images-detail-page,
 :failure #error {
 :cause "Something wrong with the front-page"
 :via
 [{:type java.util.concurrent.ExecutionException
   :message "java.lang.Exception: Something wrong with the front-page"
   :at [java.util.concurrent.FutureTask report "FutureTask.java" 122]}
  {:type java.lang.Exception
   :message "Something wrong with the front-page"
   :at [paintings2.api_get$get_data_front_page invokeStatic "api_get.clj" 128]}]
 :trace
 [[paintings2.api_get$get_data_front_page invokeStatic "api_get.clj" 128]
  [paintings2.api_get$get_data_front_page invoke "api_get.clj" 121]
  [paintings2.api_get$get_data_detail_page invokeStatic "api_get.clj" 134]
  [paintings2.api_get$get_data_detail_page invoke "api_get.clj" 131]
  [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" 266]
  [java.util.concurrent.ThreadPoolExecutor runWorker "ThreadPoolExecutor.java" 1142]
  [java.util.concurrent.ThreadPoolExecutor$Worker run "ThreadPoolExecutor.java" 617]
  [java.lang.Thread run "Thread.java" 745]]}}
{:sym paintings2.api-get/get-art-object}
{:sym paintings2.api-get/get-image-url}
{: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-page"
 :via
 [{:type java.util.concurrent.ExecutionException
   :message "java.lang.Exception: Something wrong with the front-page"
   :at [java.util.concurrent.FutureTask report "FutureTask.java" 122]}
  {:type java.lang.Exception
   :message "Something wrong with the front-page"
   :at [paintings2.api_get$get_data_front_page invokeStatic "api_get.clj" 128]}]
 :trace
 [[paintings2.api_get$get_data_front_page invokeStatic "api_get.clj" 128]
  [paintings2.api_get$get_data_front_page invoke "api_get.clj" 121]
  [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" 266]
  [java.util.concurrent.ThreadPoolExecutor runWorker "ThreadPoolExecutor.java" 1142]
  [java.util.concurrent.ThreadPoolExecutor$Worker run "ThreadPoolExecutor.java" 617]
  [java.lang.Thread run "Thread.java" 745]]}}
=> {:total 7, :check-passed 5, :check-threw 2}

roelof16:02:52

maybe someone else sees why this test is failing and if I do the test alone it is a success

alexmiller17:02:15

so you can’t reproduce it with (stest/check ‘paintings2.api-get/fetch-paintings-and-images-front-page) ?

alexmiller17:02:49

I still see the pmap in there too in the stack trace, so doesn’t seem like you’ve removed it (or maybe need to reload)

roelof17:02:58

then I see the same error

roelof17:02:54

moment, I will fire up a new repl

roelof17:02:10

and going try the test of fetch again

alexmiller17:02:13

is this right?

alexmiller17:02:15

(s/fdef fetch-paintings-and-images-front-page
 :args (s/cat :args (s/coll-of ::objectNumber))
 :ret (s/coll-of (s/and :basic/artObject :image/object)))

alexmiller17:02:39

shouldn’t it be a :ret of (s/coll-of (s/or :basic/artObject :image/object)) ?

alexmiller17:02:05

same thing on the fdef for fetch-paintings-and-images-detail-page

roelof17:02:57

no,, this function needs to contain the output of artobject and a image/object

roelof17:02:17

@alexmiller I could improve it but I have no idea how. I check there for two things if the id and the title are both present

alexmiller17:02:19

I would improve the throw on line 138 to include the explain of the failure

roelof17:02:42

so both or one of the two could fail

alexmiller17:02:10

(throw (ex-info (str "Something wrong with the front-page" id) (s/explain-data ::artObject art-object)))

alexmiller17:02:34

then you’ll get the explanation describing the failure in your exception message above

roelof17:02:14

oke, changed, Will now try it on a repl

roelof17:02:18

and is running

alexmiller17:02:07

that vector of list of vector in the input still looks fishy to me

roelof17:02:26

I think this is what we are looking for :

:data #:clojure.spec{:problems [{:path [], :pred map?, :val nil, :via [:paintings2.api-get/artObject], :in []}]} 

alexmiller17:02:03

so it’s nil

alexmiller17:02:25

and nil is not a valid artObject

roelof17:02:32

you mean artObject is nill ?

alexmiller17:02:09

get-data-front-page is being invoked with nil

roelof17:02:13

that is a problem. Artobject is not allowed to be nil

roelof17:02:32

si I have to rethink my spec's

alexmiller17:02:41

so then you need to back up a step or two - fetch-paintings-and-images-front-page is being called with generated ids. ƒor each one, you’re invoking read-json-data, then get-art-object, then get-data-front-page (which receives nil)

roelof17:02:31

I think I have to rethink my specs. When I run my this site every things works fine

alexmiller17:02:43

the generator is creating random ids - I assume these ids are likely not to map to real things

roelof17:02:45

ArtObject is never nill in real

alexmiller17:02:01

when that happens, you’re getting nil and passing it down the line

alexmiller17:02:30

so you might need to constrain the generator for the args in fetch-paintings-and-images-front-page to just objects that actually exist

roelof17:02:36

there we have it . I assume that the specs are calling the real external api

roelof17:02:50

when the ids are not real ids for the external api , then the outcome is nill

alexmiller17:02:35

another option is to use stest/instrument and the :replace option to mock your api call and force it to return something known

roelof17:02:50

I think I need a way to use real ids in the specs so I need the outcome of get-object-numbers

roelof17:02:24

oke, and then I can use one of more object-numbers that I know ?

roelof17:02:09

I will dive again in the spec guide how to use the replace option

alexmiller17:02:26

that’s using instrument to mock a service call

alexmiller17:02:42

but sounds like you were suggesting the path of modifying the spec generator

alexmiller17:02:15

you can do that in a targeted way by supplying a custom generator for the args spec of the function call

alexmiller17:02:29

gotta run...

roelof17:02:21

me too, time for dinner

roelof18:02:12

@alexmiller if you bee around again. Can you help me figure out how I can stub here the service call.

roelof18:02:49

I think we need to stub two services. One for fetching the ids and one for fetching the rest

roelof18:02:02

or can I just do

(stest/instrument `invoke-service {:stub #{xxxxx}}) 

josh_tackett18:02:07

Hey what does a ~ mean before a variable?

roelof18:02:39

where xx is I think the read-numbers function

roelof18:02:09

@josh_tackett is there also a ' ?

josh_tackett18:02:19

just ~organization

roelof18:02:41

hmm, then It something else then I thought

dpsutton19:02:10

@josh_tackett can you post the full context? I"m guessing its inside of a semi-quote

roelof20:02:39

@alexmiller how can I use that service as arguments to the get-data-front-page function ?

upgradingdave22:02:09

Hi all, I have a cljs beginner type question - I have a html form where the user can choose files. Each time they choose files, it produces a js array of js File objects. I do a (array-seq files) to produce a clojure list of js File objects (called new-file-list). I’d like to be able to do this (into #{} (concat existing-files-list new-file-list))

upgradingdave22:02:07

but the problem is that I can add the same File object twice. Is there any way to define a compare fn or something to tell into #{} about how to identify duplicate Files?