This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-06-30
Channels
- # aws (1)
- # bangalore-clj (1)
- # beginners (73)
- # boot (13)
- # cider (3)
- # clara (19)
- # cljs-dev (33)
- # cljsrn (37)
- # clojure (177)
- # clojure-dev (13)
- # clojure-gamedev (1)
- # clojure-italy (10)
- # clojure-nlp (1)
- # clojure-russia (1)
- # clojure-spec (64)
- # clojure-uk (128)
- # clojurescript (177)
- # core-async (23)
- # cursive (5)
- # datascript (13)
- # datomic (20)
- # devops (49)
- # emacs (13)
- # graphql (5)
- # hoplon (13)
- # keechma (1)
- # leiningen (3)
- # liberator (4)
- # lumo (2)
- # off-topic (11)
- # om (19)
- # om-next (3)
- # onyx (6)
- # re-frame (13)
- # reagent (14)
- # ring-swagger (7)
- # rum (2)
- # spacemacs (7)
- # unrepl (1)
- # untangled (23)
- # vim (8)
- # yada (1)
is there an idiomatic way to create a keyword in the current namespace, or is (keyword (str *ns*) s)
pretty much it?
what about at compile time? is there a shortcut for a keyword in the namespace I’m writing the code in? something like ::
. I could do (keyword "app.models.user" s)
but that seems verbose and potentially brittle to refactoring
if you want it to be the namspace calling your function/macro then *ns*
works - but that won't give you the ns your definition came from
*ns*
is set by the compiler when compiling code, when running code its value is arbitrary
sorry, right - it will be the arbitrary value of *ns*
at runtime for a function, but for a macro it will be the ns being defined
some execution environments preserver the value of *ns*
between compilations (the repl), but common environments do not
macro expansion happens at compile time, so macros can observe a meaningful value of *ns*
when a function is being compiled, the compiler uses *ns*
to figure out which vars it uses, but those vars are then embedded in the generated bytecode, and when the bytecode is run, it never looks at the value of *ns*
again
What we do at World Singles is to have (def ^:private my-ns *ns*)
near the top of each namespace where we need the “current namespace” and then use my-ns
instead of *ns*
.
That way it’s bound to the file’s namespace at load/compile time and doesn’t change during program execution.
why does (get-in {:a (vector {:b :c})} [:a 0 :b])
work, but (get-in {:a (list {:b :c})} [:a 0 :b])
doesn’t?
there's #beginners
Depends on the audience and the time of day. But we try to encourage focus to ask beginner Qs in #beginners so folks can opt-in/-out.
What I remember of clojure IRC was that you were free to ask beginner questions. I know because I asked many of them. I'm not sure the distinction. I'm still a beginner.
@devn We're all beginners on different topics 🙂 The main difference from IRC (apart from the wonderful Slack UI/UX) is the plethora of channels here... (and this is getting meta so #off-topic if we really want to go down that path).
Hello everyone, I have an app which generates documents (for example blog posts). Each document has an ID and consists of Text, Tables, Lists etc. and is completely defined in EDN. I want to store these documents but due to not consistent, changing keys it is not easy to store this in a RDBMS-Table. So at the moment I have a table in my h2db which has two colums "ID" and "data", where data is a cblob and stores the edn serialized as a string.. Is there a better "clojury"-way to store edn documents?
@burke Maybe serialize it using something like https://github.com/ptaoussanis/nippy/blob/master/README.md
@burke there’s also https://github.com/cognitect/transit-format which is what we’re using which is a good fit if you want to use it in a browser because it can be used on top of json
@mkvlr @burke However, transit isn't for storing data (yet) > NOTE: Transit is a work in progress and may evolve based on feedback. As a result, while Transit is a great option for transferring data between applications, it should not yet be used for storing data durably over time. This recommendation will change when the specification is complete.
@curlyfry right… we just ignored that. it does seem fairly stable at this point there’s not much activity in the repo anymore. Was wondering if that recommendation was going to change…
@curlyfry I was thinking about using nippy, because of their built-in compression functionality. But my main concern is not the serializing part, but using the clob or blob for storing the data. Accessing the document doesn't feel native (sql query, reading clob, deserialize data). I hoped there was an mongodb-equivalent for clojure/edn 😅
@sundarj: but after 1 year there will be no updates and my project relys on an old unmaintained version, if I understand the description correctly?
@burke storing fressian in a BLOB or edn in a CLOB is fine as long as you don't need atomic updates or native queries, otherwise I strongly advise against it (you may then want to use JSON support in a sql db, or a document store). There is no such thing as a 'clojury' way of designing a database imho - this should be language independent :)
val_waeselynck: updates are rarely and only done from one person (the document author). Native queries aren't needed. The documents are self-contained, so there are no dependencies to other tables. But inside the document there are dependencies, thats why I was unsure if I should break the document hash-map into normalized database tables or just store the whole document in a clob just like it is stored at runtime. I think I'll stick with the clob solution.
I still think that will be awesome do something like :find ?edn :where [?e :graph/data ?edn] [(contains? ?edn :foo) true]
There is no way to make this efficient in Datomic currently
starting nREPL for the first time on this machine says "could not transfer ... unable to find valid certification path to requested target". We have a custom certificate at work that sits at top of everything. What should I do to get nREPL (is it using maven behind?) to use it when downloading artifacts? E.g. in pip
I need to add in ~/.pip/pip.conf
a line saying cert = /etc/ssl/certs/ca-certificates.crt
by nrepl do you mean leiningen?
lein does not use maven, but it speaks to the same repos, you probably need to make sure your java certificates are properly set up
@noisesmith I installed leiningen and ran cider-jack-in
in a .clj
file in emacs
right, but nrepl doesn't download things, leiningen does
anyway, depending on your OS there's various ways to make sure your java certs are OK
oh, that's the one I know /var/lib/dpkg/info/ca-certificates-java.postinst configure
or perhaps this https://stackoverflow.com/a/33440168
that did write a lot of "Replacing ..." lines and a "done." in the end which didn't solve the problem
what about the SO version?
weird - is the cert installed in such a way that ubuntu ca-certificates would know about it / use it?
because that should have fixed it if it is
https://askubuntu.com/questions/645818/how-to-install-certificates-for-command-line
no I'm saying add the ca-file to ubuntu itself
then set up java's certs from ubuntu
though, if you want to do it the tedious way you could also manually add that cert to java...
then I have no idea what's wrong here
the best option would be to add the mirrors we use for maven into my leiningen profile. I'm just not sure how to write it down. I'd need a ~/.m2/settings.xml to leiningen profile converter
this isn't maven, lein doesn't use maven
it can access maven repos... but doesn't use maven itself
sorry, misread
this should be system level config properly propagated to java, it shouldn't even be leiningen's concern
it's hard to tell where the problem lies, it could even be that the network here is deliberately blocking direct access to the repos since they want us to use the supplied mirrors
one thing to rule out would be that ca-certificates.postinst or the purge / reinstall of ca-certs didn't undo your custom cert addition
there might be a less heavy handed way to add the cert and also make sure it updates java without doing a purge / install cycle...
I managed to add our mirror to profiles.clj
but it only mirrors the maven repo, so I get the same error when I get to dependencies that are on clojars 😞
@noisesmith I found the culprit - the certificates are OK, for some reason a bad java is being used. Now I just need to find out who picked that version and why
in terms of the wrong java being installed, or the wrong one picked out of those installed?
if the latter, that can be fixed with update-alternatives
that's not what decides it is it? I mean lein just looks for the first java on path
unless nix changes that...
I'm pretty sure nix
changes it since they are all about being reproducible and immutable etc. Also command -v java
from emacs returns /usr/bin/java
which points to ubuntu java, not the nix one
using lein via a package manager seems fishy to me, sort of like using the jvm inside a container - I know there are valid reasons, but lein already manages its version better than most package managers will and the jvm already isolates differences between environments...
Hi, all! Does anyone have some good recommendations on resources covering/showing proper use of records and protocols? I’ve been using Clojure happily for three years without them, mostly on a hobby basis, and feel that I understand them pretty well, but when I start using them or thinking about how to do it, I feel like I’m going all OOP. Hopefully the question makes sense.
@mokr I cover this a bit in my presentations about Component https://stuartsierra.com/presentations
@stuartsierra Thanks, I’ll have a look.
A follow up question: In my current project where I believe records/protocols is the good fit, I start out with CSV records with lots of fields. Many are not always present. Is it ok to create a record with just a few fields as required (eg. “logtime” and “id”) and the rest as optional, event though many other fields are highly useful and used in calculation?
that's a pretty normal way to use records - adding fields that aren't defined on them
but if you know what they will all be, you could just have them all nil by default...
@noisesmith Thanks. What’s the benefit of having them be nil? Would that make the generated ->MyRecord requiring a lot of paramters, and possibly not making it a MyRecord if you use map->MyRecord if you provide a map missing some keys?
@mokr Records are usually indicated when you also have Protocols (or interfaces) and you plan to have multiple different types of records implementing the same functions for polymorphic behavior.
@mokr map->MyRecord always makes a MyRecord, even for an empty map
and yes, with more than ~4 fields I would always use map->MyRecord rather than a positional constructor
@noisesmith Thanks, the former was new to me. I guess I need to experiment and see how it goes.
@stuartsierra I guess my “fear” is to make everything a “method” instead of a function. <- My best description of where I feel it turns strange when using a functional language.
@mokr You only need "methods" in Clojure if you need polymorphism: different behavior for different types, where the caller doesn't know which type it is.
@stuartsierra I believe that is the use case I have in my current project, hence the desire to finally dive into records and protocols. I’m using re-frame for the GUI, and tend to aim for generic code. In this case I’m presenting information where the GUI code displays :display, creates tooltip from :tooltip, sets react key from :react-key and so on. What these keys contains differs based on type. I like the way generic code makes it clearer what the code is trying to accomplish, without mixing in a lot of “how”. Now the plan is to turn these keys (:display, :toolstip, :react-key, …) into method on a protocol like “Displayable”. Anyway, thanks so much for the imput. Now I need to focus on dinner preparations.
what’s the idiomatic way to guarantee some unknown value is inside a sequence, where that value could or could not already be in a sequence?
(into [] val) ;; fails if val isnt already in a seq
(conj [] val) ;; always works but might nest, i.e. [[val...]]
(if (sequential? val) val [val])
flatten is terrible
generally the best answer though is to arrange your data so this doesn’t occur in the first place
the best thing is to not write code that sometimes returns a collection and sometimes a single item (but I realize you aren't always the one who implemented the source of the data)
things that are either <foo> or <collection of foo> tend to be always broken and/or special cased
^ agree with alexmiller, except in this case it’s relating to an (assoc
vs an (assoc-in
.. as in someone might hand me a value to put at [:foo :bar]
or just :bar
and they create contagious complexity in consuming code...
@lwhorton there's a reason assoc and assoc-in are two different functions though
if you’re familiar with http patch semantics, i’m trying to implement something following the {:op "replace" :path "/foo/bar" :value "bob"}
. the issue is with :path
, which could be some arbitrarily nested path into a resource
so i figure assoc-in with a “guaranteed to at least be a sequence” is a good solution
always turn path into a collection, even if it's a one item coll
does anyone know of alternatives to slingshot for easily creating custom exceptions, or is it pretty much “de facto” if you don’t want to compile a bunch of custom exception types?
@lwhorton i think of e.g. transforming a scalar to a single element collection as desugaring that happens in the first layer of code that processes some input
@cpmcdaniel - I've used hara.event
before and enjoyed it. It's a little more than custom exceptions, though. It changes how control flow works with exceptions to be more like how Common Lisp does exceptions.
Hi all, Is there any way to create a hashmap interactively. I mean, I have the keys and values in separate lists and I need to associate as a hashmap
Want to share code? Could you just wrap your method into a lazy-seq? a list where each item is the result of a function is still a list.
@alricu aside from the other excellent answers, if your inputs are [:a :b :c] and [1 2 3] this is exactly what zipmap is for
also, please don't use :1
- the clojure reader accepts this keyword, but it's not actually valid, it's perfectly acceptable to use a number as a key in a hash-map if that's what you need
Why isn't :1
valid?
the reader accepts it but the clojure docs rule it out
which means that in the future the reader might stop accepting it
I admit that's unlikely, but when we have the choice, I think it's better to not use things that clojure claims it shouldn't accept
@eriktjacobsen for example cljs read-string doesn't allow it
and that's not a cljs bug, since clojure's docs already say it's not valid
there's lots of things that accidentally work in clojure, but we shouldn't assume are intended
+cljs.user=> (cljs.reader/read-string ":1")
TypeError: Cannot read property '0' of null
+cljs.user=> (cljs.reader/read-string ":a")
:a
i’m currently diagnosing some garbage collection issues and am wondering if maybe i should be using the oracle jvm instead of openjdk
i cant find any evidence that it matters but i cant say for sure
does anyone have any opinions on thi?
no, im looking into very long stop the world pauses ~20 secs
i guess im wondering if the implementation of garbage collectors makes a difference
ok i just wanted to hear someone say it wont make a difference because that’s my instinct too
while we’re on the topic, just so i’m clear, the implementation of g1 garbage collector in openjdk is different than the implementation in oracle jvm right?
it is not different @jaydeesimon
ok thank you for clarifying that
the choice of GCs makes a difference with pause times, and your allocations are going to be workload dependent...
i've found usually that there's an offending spot in my code, but it can be tricky to track sometime
A quick temporary fix for long pause times is to a) make your max heap size smaller and b) remove any JVM command line flags that somebody pasted into your deployment (probably directly from stack overflow)
I was almost going to mention that making the heap smaller thing, but then I realized it sounded really weird and I didn't have a cite... thanks for confirming that though
also, I recently learned the term "jvm smoke break" for this kind of problem, which I find amusing
the advice is totally counterintuitive. mem leak => long GC => increase heap size => larger leak => longer pause time
Hi! Is Clojure 1.9 stable enough to start a project on it now which will be pushed to production in a couple of months?
@ghadi which heap profilers do you recommend?
@hmaurer looks pretty stable to me: https://github.com/clojure/clojure/graphs/contributors?from=2017-01-01&to=2017-07-01&type=c