This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-12-29
Channels
- # adventofcode (4)
- # beginners (113)
- # boot (165)
- # cider (192)
- # cljsrn (82)
- # clojure (148)
- # clojure-austin (6)
- # clojure-russia (22)
- # clojure-spec (45)
- # clojure-uk (19)
- # clojurescript (153)
- # core-async (5)
- # cursive (7)
- # datomic (2)
- # defnpodcast (2)
- # emacs (1)
- # hoplon (617)
- # instaparse (10)
- # lein-figwheel (19)
- # luminus (2)
- # off-topic (12)
- # om (3)
- # onyx (36)
- # pedestal (1)
- # protorepl (43)
- # re-frame (8)
- # ring (7)
- # specter (17)
- # testing (2)
- # untangled (117)
- # yada (12)
Hi all. is there a preferred clojure style guide that you would recommend? I found this but not sure how close it is to what the community does https://github.com/bbatsov/clojure-style-guide#naming
I have this code :
defn home-page [page]
(let [page-num (s/conform ::page page)
url ""
options {:as :json :query-params {:key (env :key) :format "json" :type "schilderij" :toppieces "True" :p page-num :ps 10}}]
(if (s/invalid? page-num) 1 page-num)
(layout/render
"home.html" {:paintings (-> (client/get url options)
api/read-numbers
api/fetch-paintings-and-images-front-page)})))defn home-page [page]
(let [page-num (s/conform ::page page)
url ""
options {:as :json :query-params {:key (env :key) :format "json" :type "schilderij" :toppieces "True" :p page-num :ps 10}}]
(if (s/invalid? page-num) 1 page-num)
(layout/render
"home.html" {:paintings (-> (client/get url options)
api/read-numbers
api/fetch-paintings-and-images-front-page)})))
is there a way I can make it work to not apply fetch-paintings-and-images-front-page only when read-numbers returns something otherwise then nil. I could put read-numbers in a if-then but then that function gets executed several times.
@sneakypeet That guide is made with help from the community and I highly recommend it!
sweet thank you
I got trouble in optimization, described here https://twitter.com/jiyinyiyong/status/814165501924360192
Why is this one failing on string? :
(s/explain ::objectNumber [{:objectNumber "sk-c-5"}])
val: [{:objectNumber "sk-c-5"}] fails spec: :paintings2.api-get/objectNumber predicate: string?
@dpsutton here are all the specs :
(def id-regex #"[a-z]{2}-[a-z]-\d{1,2}")
(s/def ::id-type (s/and string? #(re-matches id-regex %)))
(s/def ::objectNumber ::id-type)
(s/def ::id-list (s/coll-of
(s/keys :req-un [::objectNumber])
:kind vector?))
so object number expects a string of a certain format and you passed it a vector of maps?
How must I change this : (s/keys :req-un [::objectNumber])
so this one will be valid :
(s/explain ::objectNumber-list [{:body{:artObjects{:objectNumber "sk-c-5"}}}])
@roelof That data structure is not a ālist of object numbersā. It is a list of maps containing a :body
key. And the :body
in this case is a map with an :artObjects
key. And that in turn would need a spec (that references ::objectNumber
). So you need a whole stack of specs here that you can nest to match the overall structure.
oke, so for each step I need to make something like this :
(s/def ::objectNumber-list (s/coll-of
(s/keys :req-un [::objectNumber])
:kind vector?))
You have to describe the data structure you expect ā and you have a nested data structure: it is not just a collection of maps with :objectNumber
as a key ā it is more deeply nested than that.
I understand , I try to say I have to think well how to describe the nested data structure
I can make a def with one level and and another with the next level but I have to think how I can tell how the second is a part of the first
@seancorfield can you give a hint how I can do that ?
Hello, I have a little problem with Clojure-Nginx server config again. Could you help me? My error message here:
Could this trick :
(s/def :animal/dog (s/merge :animal/common
(s/keys :req [:dog/tail? :dog/breed])))
@roelof Think about it step by step. What would be a spec for the :artObjects
sub-expression? Then how would that spec be used to define a spec for :body
? Your [{:body {:artObjects {:objectNumber āx-a5ā}}}]
is a coll-ection of :art-object/body
data structures, yes? and :art-object/body
isā¦ what? Itās a mapā¦ so it has keys (well, if it is a map? I would have expected it to be a coll-ection of ::art-object
which in turn was a map, with some keys which include ::objectNumber
?)
(note that Iām using :art-object/body
as a spec name to distinguish it from other types of :body
data structures you are processing ā you can use a namespace qualifier with keys in :req-un
to tell unqualified keys apart in different contexts)
@seancorfield thanks for that explanation. I have not looked it that way
I'm trying to require clojure/math.numeric_tower
in a file, but I can't figure out the correct syntax. It works in the repl
(require '[clojure.math.numeric-tower :as math])
but
(:require [clojure/math.numeric_tower :as math]
in a file doesn't work šIt seems it works in lein repl
but not in cider nrepl
. I'll shut everything down and try again.
whereas for "cider nrepl" you are editing a file so you're putting the (:require [...])
form inside your ns form?
yeah. I ran lein deps
; it seems to be in the classpath too. I also checked the installation folder.
i have a situation where I run out of memory (an advent of code example where I build up a massive persistent vector over many iterations) now I wonder is there a way to tell clojure to create a ānewā persistent vector every time instead of doing structural sharing?
i have tried making it transient
but then some of the functions no longer work, seems like there is no rseq!
or concat!
but maybe iām doing sthg wrong š
@dpsutton iām not sure if i understand the behaviour of structural sharing in the data structures but i am basically mutating the persistent vector all the time and turning all values into completely different values with every iteration
so I expect that without structural sharing and with creating an entirely new data structure every time it would use less memory
but iām unclear how to figure out whether my code right now is actually holding on to the data/using structural sharing or not š
my understanding is the bits no longer shared can be GC'd so structural sharing is always (TM) as compact as possible
makes sense, it might also be possible that i just need more memory in general because the vector is simply to large
http://stackoverflow.com/questions/22038455/is-it-a-good-idea-to-force-garbage-collection-in-clojure
@tosh sounds like your code is āholding onto the headā of a data structure rather than just processing it?
jinx š
I hate pinging people in beginners who aren't actively in the conversation. I was just hoping you could lend your experience š
Did a link to the code in question get posted? It may just be runaway recursion or a loop? Although if the data structure truly is āmassiveā and needs to be, then maybe itās just a question of raising the JVM heap limit...
ah sry, this is my code right now https://gist.github.com/tosh/805a75755bdb393ec7f4710cf8d032ed
i think on a meta level there is probably a more clever way to solve it if i read up on dragon curves (hint in the advent of code riddle description)
peter norvigās python version solves part 2 almost instantly for me http://nbviewer.jupyter.org/url/norvig.com/ipython/Advent%20of%20Code.ipynb#Day-16-Dragon-Checksum
i chose to model the problem with a persistent vector containing booleans whereas he is using strings