This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-12-24
Channels
- # adventofcode (13)
- # beginners (163)
- # boot (8)
- # cider (1)
- # clojure (86)
- # clojure-germany (1)
- # clojure-italy (2)
- # clojure-spec (66)
- # clojure-switzerland (1)
- # clojure-uk (25)
- # clojured (1)
- # clojurescript (58)
- # core-async (1)
- # cursive (4)
- # datomic (11)
- # events (1)
- # funcool (3)
- # hoplon (86)
- # off-topic (8)
- # om (11)
- # onyx (1)
- # protorepl (7)
- # re-frame (15)
- # ring-swagger (4)
If the inline repl was connected and it was an evaluation issue, then probably right next to the line. Otherwise there might be a little red number to the bottom right of the window, which will open the console if you click it
Hmm, silly question but did you trigger the inline evaluation with Ctrl-Enter or whole file evaluation with ctrl-shift-enter?
Yes, to some degree fixed, I just think I don't know how to properly trigger what I need
You can always explore possible commands from the command panel, which can be accessed via ctrl-space
Answer is i can choose the profile with lien with-profile
which leads to some slightly wonky commands:
lien with-profile test test
for instance -_-
meanwhile, yea for auto reloading tests!
Im confused what this line does [page nil page-num (or (s/conform ::optional-page page) 1)]
@sveri sean have shown some examples :
boot.user=> (let [page nil page-num (or (s/conform ::optional-page page) 1)] page-num)
1
and
boot.user=> (let [page "42" page-num (or (s/conform ::optional-page page) 1)] page-num)
42
when there is a valid pagenumber , it will be converted to a long of the page variable in a url
I have problems to see how it fits in this code :
defn home-page [page]
(let [page-num (or (read-string page) 1)
url ""
options {:as :json :query-params {:key (env :key) :format "json" :type "schilderij" :toppieces "True" :p page-num :ps 10}}]
(layout/render
(if (s/invalid? page-num)
(println "pagenumber is not right")
"home.html" {:paintings (-> (client/get url options)
api/read-numbers
api/fetch-paintings-and-images-front-page)}))))
@sveri it it right that the line (page-num (or (read-string page) 1)
has to be deleted because it does the same as the line I want to use ?
This is also wrong :
(defn home-page [page]
(let [ [page-num nil page (or (s/conform ::optional-page page) 1)] page
url ""
options {:as :json :query-params {:key (env :key) :format "json" :type "schilderij" :toppieces "True" :p page-num :ps 10}}]
(layout/render
(if (s/invalid? page-num)
(println "pagenumber is not right")
"home.html" {:paintings (-> (client/get url options)
api/read-numbers
api/fetch-paintings-and-images-front-page)))
See, you said you wanted to learn something, thats why you redo it in clojure. And again I am telling you, you learn by reading and applying the things you read
I think it is already in a single function :
(defroutes home-routes
(GET "/" [page] (home-page page))
(resources "/")
@sveri so something like this :
(defn page-check [page]
(let [page page page-num (or (s/conform ::optional-page page) 1)] page-num))
(defn home-page [page]
(let [pagenum (page-check page)
url ""
options {:as :json :query-params {:key (env :key) :format "json" :type "schilderij" :toppieces "True" :p page-num :ps 10}}]
(layout/render
(if (s/invalid? page)
(println "pagenumber is not right")
"home.html" {:paintings (-> (client/get url options)
api/read-numbers
api/fetch-paintings-and-images-front-page)}))))
I do not get it . I have this code :
(defn page-check [page]
(let [page page page-num (or (s/conform ::optional-page page) 1)] page-num))
(defn home-page [page]
(let [url ""
options {:as :json :query-params {:key (env :key) :format "json" :type "schilderij" :toppieces "True" :p page-num :ps 10}}
(layout/render
"home.html" {:paintings (-> (client/get url options)
api/read-numbers
api/fetch-paintings-and-images-front-page)})]))
and still I see this :
Caused by: clojure.lang.ExceptionInfo: Call to clojure.core/let did not conform to spec:
In: [0 4] val: (layout/render "home.html" {:paintings (-> (client/get url options) api/read-numbers api/fetch-paintings-and-images-front-page)}) fails spec: :clojure.core.specs/local-name at: [:args :bindings :binding :sym] predicate: simple-symbol?
it has nothing to do with spec itself, you could remove all the spec stuff in your source file and still get that error
defn home-page [page]
(let [page-num (or (read-string page) 1)
[page nil page-num (or (s/conform ::optional-page page) 1)] page-num
url ""
options {:as :json :query-params {:key (env :key) :format "json" :type "schilderij" :toppieces "True" :p page-num :ps 10}}]
(layout/render
(if (s/invalid? page-num)
(println "pagenumber is not right")
"home.html" {:paintings (-> (client/get url options)
api/read-numbers
api/fetch-paintings-and-images-front-page)}))))
especially this line: [page nil page-num (or (s/conform ::optional-page page) 1)] page-num
This is working :
(defn home-page [page]
(let [page-num (or (read-string page) 1)
url ""
options {:as :json :query-params {:key (env :key) :format "json" :type "schilderij" :toppieces "True" :p page-num :ps 10}}]
(layout/render
"home.html" {:paintings (-> (client/get url options)
api/read-numbers
api/fetch-paintings-and-images-front-page)})))
The only thing is that users can change it to numbers which are bigger then 470 or smaller then 1
but I want to check also for nil and the 1 and 470 pages and sean suggest to me to use spec
especially with this error message: Caused by: clojure.lang.ExceptionInfo: Call to clojure.core/let did not conform to spec: In: [0 4] val: (layout/render "home.html" {:paintings (-> (client/get url options) api/read-numbers api/fetch-paintings-and-images-front-page)}) fails spec: :clojure.core.specs/local-name at: [:args :bindings :binding :sym] predicate: simple-symbol?
oke, I change it to this : ` (defn home-page [page]
(let [url "https://www.rijksmuseum.nl/api/nl/collection"
options {:as :json :query-params {:key (env :key) :format "json" :type "schilderij" :toppieces "True" 😛 page :ps 10}}]
(layout/render
"home.html" {:paintings (-> (client/get url options)
api/read-numbers
api/fetch-paintings-and-images-front-page)})))
oke, so now I can add the spec files and hopefully I can check the url parameter page now well
and do like I said, leave the page number part in its own function, so you can test it easily
It works finally :
(page-check nil)
=> 1
(page-check 1)
=> :clojure.spec/invalid
(page-check "1")
=> 1
(page-check 23)
=> :clojure.spec/invalid
(page-check "23")
=> 23
(page-check "500")
=> :clojure.spec/invalid
I could send it to a 404 error page or make it work that a user gets send back to the homepage without any errors
That would be a problem , The input is a seq of maps with some keywords and the output will also be a vector of id's
Last question before X-mas night. Can I have something like invalid as return for a spec function test ?
@roelof There are different spec functions, one of them returns true or false depending if the data conforms to the spec.
@sveri , I think you mean valid?
(s/valid? nil? nil) ;; true
(s/valid? string? "abc") ;; true
(s/valid? #(> % 5) 10) ;; true
(s/valid? #(> % 5) 0) ;; false
(import java.util.Date)
(s/valid? inst? (Date.)) ;; true
How do I tell that the args: are strings or integers . I tried (s/cat string? ::page :page) but that one gives this error : Assert failed: cat expects k1 p1 k2 p2..., where ks are keywords