This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-04-11
Channels
- # aleph (1)
- # architecture (18)
- # beginners (57)
- # boot (13)
- # cider (47)
- # cljs-dev (28)
- # cljsjs (13)
- # cljsrn (39)
- # clojure (258)
- # clojure-greece (16)
- # clojure-italy (2)
- # clojure-miami (1)
- # clojure-nl (9)
- # clojure-poland (15)
- # clojure-russia (369)
- # clojure-spec (53)
- # clojure-uk (49)
- # clojureremote (3)
- # clojurescript (135)
- # core-matrix (1)
- # cursive (11)
- # datascript (3)
- # datomic (4)
- # emacs (12)
- # figwheel (13)
- # hoplon (7)
- # interop (7)
- # jobs-discuss (33)
- # lumo (28)
- # off-topic (15)
- # om (7)
- # onyx (26)
- # pedestal (10)
- # perun (1)
- # planck (10)
- # re-frame (54)
- # reagent (16)
- # ring (5)
- # ring-swagger (50)
- # rum (2)
- # spacemacs (2)
- # unrepl (125)
- # untangled (12)
I"m noticing an interesting issue, and i'm not sure if it's a bug or not. When I create a profiles.clj in my projects folder, and add stuff to override things for my :dev environment, it doesn't appear to be merging with the project.clj's :profile section, and instead overwrites the entire section. Is this intentional behaviour?
I was expecting the project.clj's :profile :dev section to be merged with the profile.clj's :dev section. It seems to be completely wipe out my project.clj's :profile :dev section
ie. my profile.clj has {:dev {:env { :secret-key "abc" }}}
and my project.clj has {:profiles {:dev {:dependencies [...]}}}
when I start up a repl, the dependencies disappear, and my user.clj can't find them. If I rename profiles.clj --> _profiles.clj, everything works again, minus the secret-key that I wanted to define
>Remember that if a profile with the same name is specified in multiple locations, only the profile with the highest "priority" is picked – no merging is done
generate a string where id in (?,?,?,?)
and then (apply jdbc/query ... ids)
?
not that I know but would be happy to learn if there is
I'm not sure if all databases support this feature (`?` placeholders that expand to multiple values)
(let [#:omg-im-not-typing-this{:keys [display-name]} {:omg-im-not-typing-this/display-name "Mars"}]
display-name)
(let [#:omg-im-not-typing-this{:keys [display-name] :as m} {:omg-im-not-typing-this/display-name “Mars”}]
display-name)
ExceptionInfo Call to clojure.core/let did not conform to spec:
In: [0 0] val: #:omg-im-not-typing-this{:keys [display-name], :as m} fails spec: :clojure.core.specs/local-name at: [:args :bindings :binding :sym] predicate: simple-symbol?
In: [0 0] val: #:omg-im-not-typing-this{:keys [display-name], :as m} fails spec: :clojure.core.specs/seq-binding-form at: [:args :bindings :binding :seq] predicate: vector?
In: [0 0 1 0] val: :omg-im-not-typing-this/as fails spec: :clojure.core.specs/local-name at: [:args :bindings :binding :map :mb 0 :sym] predicate: simple-symbol?
In: [0 0 1 0] val: :omg-im-not-typing-this/as fails spec: :clojure.core.specs/seq-binding-form at: [:args :bindings :binding :map :mb 0 :seq] predicate: vector?
In: [0 0 1 0] val: :omg-im-not-typing-this/as fails spec: :clojure.core.specs/map-bindings at: [:args :bindings :binding :map :mb 0 :map] predicate: coll?
In: [0 0 1 0] val: :omg-im-not-typing-this/as fails spec: :clojure.core.specs/map-special-binding at: [:args :bindings :binding :map :mb 0 :map] predicate: map?
In: [0 0 1 0] val: :omg-im-not-typing-this/as fails spec: :clojure.core.specs/ns-keys at: [:args :bindings :binding :map :nsk 0] predicate: (-> % name #{"syms" "keys"})
In: [0 0 1 1] val: m fails spec: :clojure.core.specs/ns-keys at: [:args :bindings :binding :map :nsk 1] predicate: vector?
In: [0 0 1 0] val: :omg-im-not-typing-this/as fails spec: :clojure.core.specs/map-bindings at: [:args :bindings :binding :map :msb 0] predicate: #{:as :or :syms :keys :strs}
:clojure.spec/args ([#:omg-im-not-typing-this{:keys [display-name], :as m} #:omg-im-not-typing-this{:display-name "Mars"}] display-name)
clojure.core/ex-info (core.clj:4725)
No, also IMO namepsacing doesn't make sense in this case. It's another step to parse for the programmer, and you only use it once.
@rauh ah interesting, ok; I literally just discovered this works at all after using namespaced maps for months 🙂
(let [#:omg-im-not-typing-this{foo :display-name} {:omg-im-not-typing-this/display-name "Mars"}]
foo)
Don’t mess too much with destructuring - it is in Clojure as an afterthought
@rauh but I see what you mean about namespacing the :as as to why it’s not supported in the first place
(let [{x (inc 2) y x} {3 8, 8 19}]
y)
=> 19
(let [{x (inc 2) a x b 1 c 2 i a} {3 8, 8 19}]
a)
=> 19
(let [{x (inc 2) a x b 1 c 2 d 3 e 4 f 5 g 6 h 7 i a} {3 8, 8 19}]
a)
CompilerException java.lang.RuntimeException: Unable to resolve symbol: a in this context
@clojureman I would not go that far to say it’s an afterthought 🙂
This shows how it is glued on to the language - and actually works quite well anyhow
@raspasov, the story is that it is - though I do not remember where I read it
Something that Rich thought about for a a day or something, then came up with the current solution
that's not the case at all -- you're thinking of something else and that's even a misquote
grep for "one-line commit" in https://clojure.org/news/2012/02/17/clojure-governance
@bronsa, it seems you are right about this - that it is sequential map destructuring that came about in a very small commit. Still the entire destructuring has a definite “glued on" feeling to it, largely because of the “extra” application-specific semantics that are (wisely) not mentioned in the standard documentation https://clojure.org/reference/special_forms#binding-forms, and because of the non-obvious way it reads to someone new to the language. Don’t get me wrong, I love the destructuring of Clojure, but I don’t think it feels like a first class citizen of the language.
@clojureman I think in your examples you’re kinda abusing destructuring 🙂 in real life cases I’ve never used anything like that;
Not abusing - just demonstrating a point
If you undertand what’s going on in the examples, you understand destructuring in Clojure better than most programmers
but what’s the point? I think you’re exploiting an implementation detail that maps are ordered a certain way up to n-elements (don’t remember how many exactly)
I am not exploiting anything - just demonstrating a mechanism
I’ve been using Clojure for almost 4 years now, so I get most of them, yes 🙂 and from my point of view that’s abuse 😄
@mpenet, I quite agree
The code demonstrates aspects of how destructuring works, it is not something that should exist in real life
basically you’re relying on a current implementation detail that was never guaranteed to stay like it is forever
@raspasov You're relying on the way the reader generates an array map and how that is iterated over in the desctructure macro
it's very wrong and your code will likely break in future versions of clojure if you rely on that
The real problem is that destructuring is not as much a language feature as something that was shoehorned into the compiler as an afterthought. That is also why it takes some getting used to for beginners
@mpenet yeah the :or
one can be argued about, contrary from the one @clojureman is talking about
@clojureman no that's not true
ok guys/gals, enough fun discussions for tonight, let’s all do something productive, ttyl 🙂 ✌️
destructuring wasn't shoehorned as an afterthought it was a very important feature that was added in userspace
and great amounts of time went into thinking about its different features during the years
yes, sometimes it behaves weirdly if you use it in an incorrect way but.. that's on you
if there's interest : http://dev.clojure.org/jira/browse/CLJ-1676
as far as I agree with that ticket I'm afraid it's going to behard to change behaviour w/o breaking user code
altho it's probably fair to assume that most would think :or
already short-circuited so..
hey guys, i'm having trouble building lein uberjar within a container. I am getting a 502 from nexus
Return code is: 502 , ReasonPhrase:Bad Gateway.
This could be due to a typo in :dependencies or network issues.
If you are behind a proxy, try setting the 'http_proxy' environment variable.
Uberjar aborting because jar failed: Could not resolve dependencies
It builds locally but this error occurs within the container, can someone point me in the right direction? thanksI often want to do the equivalent of transduce
on a channel, with no interest in the resulting value.
An my bad way of doing this is to do: (transduce my-transducer (constantly :foo) nil input-chan)
The advantage I see here is that I can take on the output chan to ensure my input-chan is fully traversed
just use a go-loop that takes values off the channel and applies your (side-effect laden) functions to them ?
sounds like loop might be more idiomatic (longer to write tho) just to apply a function to channel values
but it's not using a transducer, but the example you provide makes me wonder if you need to use transducer at all (I guess if it used somewhere else: yes)
you can pass a transducer in to the channel when you construct it; but you will still have to arrange drainage of that channel
Hi. Somewhat noob to clojure and my first post here so Hi All! | Any suggestions for a fast non-production mostly-development-time framework for persisting clojure datastructures (maps, vectors of maps etc) on disk or in some kind of "system" (ie database or whatever the framework chooses to call itself)? Mapdb comes to mind, but maybe there are better options out there. Performance (more specifically read-performance) being the operative word here. Haven't tried datomic but I would suspect performance might be less stellar than say mapdb
@mbjarland I've been using replikativ/konserve for the past week. It's a "minimalist storage protocol" with various backends that seem's to be """Clojure's RocksDB"""
It feel very practical and useful to me, if that fits your requirements: much recommend
Hmm, initial fun with konserve 0.4.8
:
user=> (load-file "src/konserve/core.clj")
CompilerException java.lang.Exception: Cyclic load dependency: [ /konserve/filestore ]->/konserve/core->[ /konserve/filestore ], compiling:(konserve/core.clj:1:1)
user=>
seems the following is enough to trigger the error above:
(ns konserve.core
(:require [konserve.filestore :refer [new-fs-store]]))
Thinking about a new computer, I found it interesting and slightly ironic, that one of the important rationale points for Clojure made by Rich several years ago was that we need to make good use of multiple cores. And yet today I'm looking for a machine with the best possible single-core performance, because when doing development work in Clojure and ClojureScript, multiple cores aren't really getting used (beyond say 2).
Just get one with the best possible performance and don't worry about how many cores it has. Like the "old days". Even so, the other software that you're running on that same machine may use all cores.
Well, there are compromises to be had: more cores usually also means worse single-core performance, so it isn't as clear-cut.
@jrychter most impressive compile times/dev experience I've seen is with ocaml, which doesn't even support multicore (yet)
Will pedestal.kafka
be open sourced soon? https://youtu.be/_Cf-STRvFy8?t=1835
(doto (java.util.Stack.)
(.push "Latest episode of Game of Thrones, ho!")
(.push "Whoops, I meant 'Land, ho!'"))
Is this supposed to happen?
(reduce #(some-fn %1 %2) [12345] some-coll)
==> %1 = 12345
(reduce #(some-fn %1 %2) [[12345]] some-coll)
==> %1 = [[12345]]
How can I get %1 = [12345]
??
That's what I'm seeing
(And I fully agree)
I replaced it with #(do (println %1) (some-fn %1 %2))
%1 will be [12345] on the first invocation of some-fn
if that's your reduce form, there's no way it's going to be anything else
Closed repl > lein clean > lein run = works
God knows what happened there
Is there a fn similar to Scala's collect
, which takes a fn A -> B
and a collection, and returns a collection of all non-nil B's? (vec (flatten (mapv fn coll)))
seems too wordy (and I dislike having to convert vec -> list -> vec).
Hey all, I posted the following to #beginners earlier, but thought I'd repost here to subject it to more eyes!
I'm trying to pull data from Oracle using clojure.java.jdbc and then output it to csv using clojure.data.csv/write-csv.
(with-open [out-file (io/writer "out.csv")]
(csv/write-csv out-file
(map vals
(j/query ora-uri ["select * from mytable"]))
:quote? string?
:quote \" ))
I'd like to be able to specify which returned fields get wrapped in double quotes, but I'm not quite sure if it's possible
@danp 2 things: 1, I wouldn’t recommend using select *
in sql ever, but also be aware of the fact that just doing map vals
does not guarantee that you’ll get the same order of columns (since the hash-maps returned from jdbc/query aren’t ordered). By happenstance, you should get the same order of columns for each run of this code, but it’s possible that CSV files generated from this code might differ in column ordering if you run this on different machines
better off doing a (map #(select-keys % [:column1 :column2 ...]) ...)
2.) with data.csv you can’t explicitly state which columns you want to double quote…but it will by default (if you don’t provide a value for :quote?
) only quote when the data requires it, or you can just specify true
to have it always quote (which can sometimes just be the safest option)
i think maybe (map (juxt :col1 :col2 :col3) ...)
is a better way to get the ordering right
Cheers @tanzoniteblack - the * is more just me messing about before I write anything "proper". Definitely hear you on the map vals - will give it a whirl now, and the suggestion from @mtkp 🙂
@mtkp right, forgot that select-keys
returns a hash-map as well; (map #(map % [:coll1 :coll2]) ...)
is what generally ends up in my code for this, rather than juxt
, but same idea (and juxt
is probably more elegant)
Thanks @tanzoniteblack and @mtkp, that's looking much better now 🙂
With regard to querying using clojure.java.jdbc, willl the list items be guaranteed order if I use an ORDER BY clause in the SQL?
Of course
lists/vectors are ordered in clojure, jdbc/query returns a list of maps, who’s order is based off the return order from your DB (and the order by clause), so those will be ordered
Different data structure. Maps and sets are unordered, seqs, lists and vectors are ordered
I'm trying to do something useful with Clojure for work, so I want to make sure I don't make any lots of stupid mistakes!
@danp https://github.com/clojure/java.jdbc/blob/master/src/main/clojure/clojure/java/jdbc.clj#L449
so you can rely on the order of the rows returned…but don’t rely on the order of the columns returned within each row…though it might coincidentally happen to look like they’re ordered if you’re returning less than 16 columns, but it’s an implementation detail that you can’t rely on
Got it - I'm looking at the data dictionary so I can get the column order for the various source views. The task that I need it for needs to be able to accept a source view name and dump it out to CSV to provide to a customer, so getting the order right is important.
the map juxt
method that mtkp send you will guarantee the order for the CSV:`
(map (juxt :coll1 :coll2)
[{:coll1 "A" :coll2 "B"}
{:coll2 "D" :coll1 "C" }])
;; ==> (["A" "B"] ["C" "D"])
Yeah, I'll definitely be using that in a latter step but the source views have different DDLs, so I need to be able to get a list of the specific column keys to pass to juxt
in each case.
what's the right way to store a keypair used for server signatures in a web application?
if I understood correctly, to use clojure spec to validate a map I need to use qualified keywords, right?
I found a nice function clojure.walk/keywordize-keys
that transforms a map with string as keys to a map with keywords as keys
but it doesn't do qualified keywords
ah I see
but here the actual original map is just what's read from a JSON file
I could easily transform the keys to prepend "foo/" before keywordizing in a way
are you trying to generate a spec at run time based off the results of a json file? Or are you trying to read a json file at compile time to to generate a spec?
not that it really matters for your code, just curious what you're trying to do
Mm neither I just wanted to parse a json and get a format that can be validated with spec straight away
should I just implement it myself using postwalk?
or there is another way maybe?
hi all! i’ve recently started to dive into clojure and would like to contribute to an open source project as a way to get more experience and improve my clojure knowledge! could somebody recommend clojure/clojurescript projects looking for contributors, but also suitable for a beginners? I’m new to contributing to open source, and i’ve got experience as a full stack developer with rails&javascript, so web based projects would probably suit me best, although i’m open to all suggestions
@andrea.crotti there is a ticket about this btw at http://dev.clojure.org/jira/browse/CLJ-2144
I used to source a postgres driver in the project.clj to talk to an Amazon Redshift
database via jdbc
, but it appears that Amazon doesn't recommend that anymore. Before I download the redshift driver and make it a localrepo thing, is anyone using amazon redshift via a dependency in clojars or maven central? tips? examples?
most things just kind of work still using the postgres driver (it's what http://www.metabase.com/ uses as their redshift driver still, with only a few gotchas). So despite their recommendations, I still prefer to use the postgres driver just so I don't have the whole code licensing and dependency management crap that they're forcing on us by not hosting it in a maven repo somewhere
depends on your use case, obviously. My understanding is that their licensing on the driver doesn't allow for it to be distributed, so maven central / clojars is out as hosting platform
oh, that's exactly what I wanted to know. I'll stick with the pg driver then, always worked fine in the past
Ah nice @alexmiller I'm glad I'm not the only one that would have liked to have that
I got a super nooby clojure/JVM question. I get a stack overflow error when invoking a macro (I didn't write the code) with a somewhat long vector in a (let ...). It chokes on the vector, from what I can tell in the stacktrace. (Stuff like chunkedNext and chunkedMore in PersistentVector.java, chunk-rest and concat in core.clj). I am experienced enough to follow the breadcrumbs in a stack trace, but I have no clue how to reason about it. Anybody got cycles to help me figure out what to google? I'll spit out code and the stacktrace if so. I just have no idea what question to ask next or how to look closer. This is while using Overtone.
I tried a couple naive things like raising the JVM memory limit
@beatboxchad stack overflow on concat is a sign of a clojure anti-pattern which is using concat in a recursive or accumulating function
I had read about that. Maybe I should read this macro closer. It's not obvious to me... oh wait, yes it is
essentially what happens is that every call to concat adds another call the end code needs to make before accessing the value
the workaround is often to force the concatenation before recurring / returning to the accumulator
but it sounds like this is overtone’s error and not yours
Yeah. It's actually a macro from Sonic Pi which I'm backporting to Overtone, because it's code I would have eventually written after a ton of thinking
I don't see an explicit concat in there, but it does... how do I say this...
wow that’s a dirty macro, I wonder why it even bothers using `
it's a partial definition
~@ is a concat
right.
yeah I can't even use it once without it choking
in what sense is it dirty? (if you don't mind expounding)
what I mean by dirty / bothering to use
` is that just about nothing in the macro (except the @ splice I guess) is actually using the features of
`, and the macro is full of noise caused by explicit undermining ` with the ~' construct (a construct that pretty much means “I’m pulling a dirty trick here”)haha, that's good to know
well, I suppose if I read it carefully with the things you've just told me in mind I should be able to make some progress.
I might even manage to clean it up a little and send it back upstream.
I’d check out those splices, look at the forms they are splicing in (which I bet have more splices or even explicit concats in their definitions etc…)
definitely. Like I mentioned I read about that antipattern earlier but didn't recognize the concat form in the code. Now things definitely click. Thanks a ton!
you can see it by sending a
`(foo ~@[1 2 3])
to your replhaha, the bot does it funny, but exposes the thing I am talking about
thanks clojurebot!
anyway, ’`(foo ~@[1 2 3] :oh-like-this) totally works in your repl
I can't believe I didn't spot that concat form. I go too long between writing clojure. hhh
oh wait it was a smart quote - wat
(println "Booya")
obligatory playing with the bot
Does anyone have any suggestions for querying deeply nested data structures (small enough to fit into memory, big enough that walking it takes 100ms<x<200ms), outside of shoving them into datascript via e.g. intension?
yep; specter mostly works, although I feel I don’t get quite the same declarative power as I do with datascript? that might just be me misusing specter, though. Context: this is a bunch of machines with e.g. their networks, disk images; etc; I could ask questions like “show me all of the networks that had a machine that was internet-accessible and a different machine that had this version of ntpd installed on it”; whiich feels easier to express in datascript (since I get to use lvars)
@lvh what about group-by on each index you care about in parallel? with structural sharing it might not be so bad space wise
It's really more of a tree; it's not particularly balanced, but very wide as opposed to deep.
@lvh if you have particular examples I could show you the best ways to handle them
my instinct about using a graph lib is that something simpler that assumes (correctly) that your data is directed and acyclic might perform faster
there are some experimental clojure datastructure query tools, like https://github.com/halgari/odin and https://github.com/alandipert/intension, but I'm not sure if they'll be faster than specter for your job.
I have part of our build at work load a tools.namespace dependency graph and some other information in to an index created with clojure.set/index and do some analysis
@nathanmarz I might take you up on that, but I'd need to generate some realistic sample data or scrub what I have first :)
I assume skynet will result from someone being really frustrated with the aws api and trying to automate it
is there a way to interact with the DOM via clojure, or is CLJS the only viable appraoch for that?
maybe via rhino on the jvm? Any other scenario, using asynchronous calls... you might as well just be using a server/client model, serving up rpc calls of some sort from clojure on the back end.