This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-11-17
Channels
- # aws (3)
- # beginners (81)
- # boot (155)
- # capetown (2)
- # cider (32)
- # clara (14)
- # cljs-dev (40)
- # cljsrn (12)
- # clojure (158)
- # clojure-austin (5)
- # clojure-korea (6)
- # clojure-poland (1)
- # clojure-russia (63)
- # clojure-spec (45)
- # clojure-uk (75)
- # clojurescript (109)
- # code-reviews (1)
- # core-logic (12)
- # core-matrix (1)
- # cursive (36)
- # datomic (16)
- # defnpodcast (1)
- # devcards (2)
- # editors (3)
- # euroclojure (1)
- # events (3)
- # flambo (1)
- # hoplon (19)
- # javascript (4)
- # jobs (1)
- # lein-figwheel (4)
- # leiningen (1)
- # off-topic (1)
- # om (177)
- # onyx (121)
- # pedestal (14)
- # planck (19)
- # proton (3)
- # re-frame (36)
- # reagent (21)
- # remote-jobs (1)
- # ring (4)
- # ring-swagger (6)
- # spacemacs (1)
- # specter (2)
- # test-check (4)
- # untangled (9)
- # utah-clojurians (1)
- # yada (2)
Hi! I'm starting a new project and I'm considering using Clojure, in docker-based microservices. What I'm worried about is, will the JVM and its high memory allocation be an issue in the beginning, when I'm planning to run on small instances with not much RAM? I'm thinking that I'll not be able to put too many containers in the same instances, as every container will run a JVM. Any one has experiences with this? Does fine tuning the JVM mitigate the issue? Should I set a low memory limit, monitor and scale when needed?
Hey. How to write clojure.spec for a map which keywords match a specific predicate, for example, say I’d like this map to conform spec that validates keys prefixed with foo-
:
{:foo-1 “value1” :foo-bar “value2” :foo-anything “bar”}
Anyone have a clue how to achieve that without enumerating all keys explicitly? Thanks in advance for any clues.
Should I use map-of
somehow maybe?
@pawel.kapala Yeah, I think map-of
is what you want
;; From the spec guide
(s/def ::scores (s/map-of string? int?))
(s/conform ::scores {"Sally" 1000, "Joe" 500})
;=> {"Sally" 1000, "Joe" 500}
@curlyfry Thanks this is the way!
Why does the category not be printed here :
(deftype Razzie [category]
Award
(present [this recipient]
(print (str "You're really "
(:category this) " , "
recipient
))))
The (:category this) isn't meaningful for deftype a
Just say 'category'
oke, and why does it work here :
(defrecord Oscar [category]
Award
(present [this recipient]
(print (str "Congratulations on your "
(:category this) " Oscar, "
recipient
"!"))))
Keyword lookup access is built into defrecords by default but deftype has almost nothing pre-built - it's up to you to build it
You could just use category in the defrecord too (and you should)
The fields are available by name in the scope of both the record or type definition
And that is more efficient than anything else in the generated bytecode
And easier to read
@alexmiller thanks
admittedly not completely clojure related, but is there a way to reference a file from leiningen that's contained inside a maven dependency? there's a .less file in a dep that i want to include in my own project, and i can see it when i inspect the jar in ~/.m2
https://clojurians.slack.com/archives/beginners/p1479393048003420 Good to know -- I've always done (:key this)
thinking that would be the most efficient and idiomatic way to do field access in a record. I'll create some tickets in my projects to change that!
:key is definitely good outside the record, but inside, using the field name will just be a direct field reference basically rather than a call
@joshkh any file inside a jar can be loaded as a resource
assuming it’s on your classpath (specified as a dep in your project)
speaking of deps, how are different versions handled? let's say dep A relies on clojure 1.8, and another dep on clojure 1.9. are both bundled into the final jar?
@joshkh pretty sure only one version is included. The underlying maven dependency resolution machinery will choose the best version to include (I think in this case it would use 1.9). You can control which transitive dependencies to exclude using :exclusions
, check out the example here (where they bring in log4j but exclude some of log4j’s dependencies): https://github.com/technomancy/leiningen/blob/master/sample.project.clj#L48
so, for example, if you wanted to make sure your project uses clojure 1.8, you could use :exclude
to exclude the transitive clojure dependency from both dep A and B, and then add an explicit dependency on clojure 1.8 inside your project.clj. Hope that helps and isn’t too confusing 😉
Can someone explain this one :
"Notice when metadata carries over"
(= {:foo :bar} (meta (merge '^{:foo :bar} {:a 1 :b 2}
{:b 3 :c 4})))
and then its showing that the end result of the merge has the meta data still intact
but they can only be functions that take no arguments, as what arguments could cider give
i've seen a library that tucks quite a bit of stuff inside of meta data. Wasn't sure why and it didn't have to be that way, but it was
hey question this is clearly very contrived but suppose you had the form (+ '(1 2 3)) plus expects individual values so I could do (apply + '(1 2 3)) but suppose I had the equally contrived (+ '(1 2 3) 4 5) what is the best way to break the list out of the interior list?
I can do (apply + (flatten (list '(1 2 3) 4 5))) I was wondering if there was a function where I could do (somefn '(1 2 3) 4 5) and do the lot or if I should create one or if I am just doing it suboptimally
wondering if there is a generic function I could wrap '(1 2 3) that would result in it being lifted into the above function
interesting thanks
@dpsutton it is wise to include metadata in every big project in every function that you made. Or is it better only to use it in API and that sort of libraries ?
i have no idea about the answer except that my suspicion is that you should have a good reason to use meta
meta is useful only in some pretty narrow use cases
note that it can be tricky to know what fns preserve meta and which do not
and that meta is not considered when comparing for equality
almost every time I have used or seen someone use meta they ultimately found that what they were putting in meta was important enough that it really should be treated as data, not metadata
that said, var and ns meta is pretty useful in the language itself
the primary reason you will use meta in most Clojure code is to apply things like type hints or ^:private to vars