This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-04-13
Channels
- # beginners (42)
- # boot (33)
- # cider (4)
- # clara (1)
- # cljs-dev (2)
- # clojars (3)
- # clojure (207)
- # clojure-boston (1)
- # clojure-france (3)
- # clojure-india (7)
- # clojure-miami (1)
- # clojure-nl (8)
- # clojure-poland (13)
- # clojure-russia (102)
- # clojure-spec (22)
- # clojure-uk (37)
- # clojureremote (15)
- # clojurescript (229)
- # cursive (9)
- # datomic (1)
- # emacs (7)
- # figwheel (2)
- # funcool (1)
- # garden (1)
- # hoplon (7)
- # jobs (12)
- # jobs-discuss (27)
- # juxt (2)
- # leiningen (6)
- # luminus (9)
- # lumo (18)
- # off-topic (3)
- # onyx (9)
- # re-frame (54)
- # reagent (5)
- # remote-jobs (3)
- # ring (3)
- # rum (3)
- # specter (28)
- # yada (30)
in fact, if you treat the two source bodies as a merge conflict, it should write itself haha
Good morning #clojure! Is garbage collection something to be careful of with core.async?
Say I create a chan, tap into a few mult and pass it back to the user. If the user just (<! (do-some-query))
will the chan be closed when it goes out of scope?
could someone explain this binding https://clojuredocs.org/clojure.core/binding in a more simple way?
I'm trying to do things like (not-any? (binding (string/includes? xxx) yyyy)) but don't know / not sure how to bind it
what do you actually want binding to do?
it's like let, but it replaces variables that have been marked :dynamic inside a specific scope for only one thread
if string/includes? doesn't exist, and isn't dynamic, that code will never work
right - or someone does
and it needs a vector (like let, or anything else in clojure that creates bindings)
(binding [*foo* some-other-thing] (code-that-uses-foo ...))
which brings me back to the initial question of what you are trying to do
i have an array of string, I'm trying to find the occurance of one or more match of specified keyword
you don't need binding for that at all, if you are searching for substring matches with string/includes? it would be something like (filter #(string/includes? % "...") arr)
i can't understand what's "#(string/includes? % "...") " for......it that a predicate?
it's a shorthand for fn
(fn [s] (string/includes? s "..."))
is there a more comphrensive guide that I can read all these common use ways to use clojure?
clojure for the brave and true is popular, there's also aphyr's clojure from the ground up http://www.braveclojure.com/
@lvh did you ever figure out the Could not locate clojure/core_instant18__init.class or clojure/core_instant18.clj on classpath.
problem? I just ran into it myself (w/ clojure 1.9.0-alpha15)
https://clojurians-log.clojureverse.org/clojure/2017-04-01.html#inst-2017-04-01T20:06:27.716762Z
@U050WMHUV hey! Yeah, clojure loads this conditionally on jdk 8 so you can't remove that file :)
I didn't remove this file; I have no idea why I see this error when switching from clojure 1.8 to 1.9
the file got added in 1.9; it seems like something is probably getting rid of it for you. Are you building uberjars?
@momofarm It sounds like you’re just getting started with Clojure? If so, you may find the #beginners channel helpful — folks there enjoy helping people learn Clojure and are willing to spend quite a bit of time helping.
@seancorfield thanks! i just start to use it few days ago, indeed i do need some help
just tried upgrading to latest clj-time and joda-time, but no luck; I'm not sure why instance18 is bring brought in (or if it should or should not be)
I’m looking for something that allows me to do this:
(interpolate "Hello ~{name}" {:name "Martin})
=> "Hello Martin"
incubator’s strint.clj doesn’t have this “named” intepolation, anyone know of a library that does?(defn replace-template [text m]
(clojure.string/replace text #"\{\w+\}"
(comp str m keyword clojure.string/join butlast rest)))
(replace-template "{hi},{hi}, lovely {w}" {:hi "hello" :w "world"})
=> #'dev/replace-template
=> "hello,hello, lovely world”
@U050TNB9F mustache? 😄
@U2BTBFQVC oh, that’s a nice and simple solution, I wasn’t aware you can provide a function as replacement, thanks!
Yes, the terseness of Clojure can be quite addictive 😀
Maybe Mustache is what I’m looking for?
like this? http://clojure.github.io/core.incubator/clojure.core.strint-api.html#clojure.core.strint/<<
@delaguardo it would get the job done but I’d prefer passing the named things as data instead of local bindings
clojure.core/load returns nil
when loading a clj file. Wouldn't it be more useful if it return a list of namespaces which got loaded instead of nil? I must be missing something here.
@U060FKQPN , makes sense. So, How can I know which namespaces are defined in the file which I just loaded using "clojure.core/load"?
@U060FKQPN that's an interesting point! Thanks for the clarification 🙂. I guess tools.namespace has a way to parse namespaces in a file, I will explore that.
yes but tools.namespace makes some very specific assumptions which usually don't hold for files that you load through load
Let me take a step back, when is it recommended to use load
? what are difference you were referring to?
Trying to update to clojure 1.9.0-alpha15, keep getting Caused by: java.lang.RuntimeException: Unable to resolve symbol: import in this context
from core_instant18.clj
@andrea.crotti @jumar @slipset Thank you very much for the emacs.
@danielstockton I use "alpha15" release without problems - could you be more specific when/how you're getting this error? In REPL? When you run the application? In Cider?
lein figwheel
lein repl
any lein command...
If I revert back to 1.8.0 everything is fine.
I deleted ~/.m2
and target/
(just in case).
@danielstockton which jvm version are you using? (a hunch)
openjdk version "1.8.0_121"
https://github.com/clojure/clojure/blob/7aad2f7dbb3a66019e5cef3726d52d721e9c60df/src/clj/clojure/core.clj#L6662-L6665 https://github.com/clojure/clojure/blob/master/src/clj/clojure/core_instant18.clj No idea why these are problematic. But this is the code.
Yeah, it seems to be the import statement. Is import no longer allowed?
it appears that for whatever reason core_instant18.clj
is being loaded in a broken ns env
I tried alpha14 too and I have the same problem.
:figwheel ~(merge {:nrepl-port 7888
:validate-config false
:ring-handler 'dev/handler}
(:figwheel config))
Is including something like this in my project.clj a big no-no? I slurp in a config file at the top. Don't know another way of having config in the project setup that isn't tracked by git.Does anyone know something similar to https://github.com/stevenvachon/broken-link-checker written on Java/Clojure?
Hey so i'm pretty stuck on something weird and was hoping someone here could give me a hand. I'm making a list of futures and I wanted to wait on each one after they wrere added to a vector. So I wrote something like this
(defn make-requests [quotes times]
(loop [left times
futures []]
(if (> left 0)
(recur (- left 1) (conj futures (quote-to-count quotes)))
(map deref futures)))
quotes)
the weird thing is that (map deref futures)
doesn't block and the program just finishes up before the futures are done
what's even weirder is that (map print futures)
shows nothing but (pmap print futures)
shows what's you'd expect (albiet a bit jumbled)
laziness? try (mapv deref futures)
additionally wouldn't you want to return the dereffed values, rather than quotes?
Is there a good reference on how to organize a Clojure projects files and directories? Just a standard desktop setup, with UI, database, logic, tests etc?
@benbot: you could use manifold.deferred/zip
to do the same:
(require '[manifold.deferred :as d])
(defn quote-n [n quotes]
(->> (repeatedly #(quote-to-count quotes))
(take n)
(apply d/zip)))
this returns a deferred (future-like thing) which will return the vector of results once dereffed@pesterhazy yeah that was in there mainly for testing.
@dm3 I'm going through a tutorial so I'm trying to stick with the limitations they gave me :/ raw clojure and futures
benbot: run! is a replacement for map that doesn't create a collection, so it's better than using dorun or doall in this case
@genec there's a lot a of ways to go about it. Look at lots of github projects. If you're looking for backend web development, your project will likely resemble something similar to a luminus template: http://www.luminusweb.net/docs#anatomy_of_a_luminus_application
thanks for the info. I've been looking a projects trying to find more of a desktop app with db connection setup. I may just go with what I'm used to from .net land.
but tooling is always evolving, so best practices around project structure is a moving target.
like now that boot is around, in addition to leiningen, you'll likely see some very different project structures.
I think boot and lein share directory structures… neither of them care about it I don’t think
is the body of a for required to be side-effect free? i.e. are there times where an item is called before we need it, or something body that is evaled twice ?
alright, so I consume the entire list and (2) the only non-pure part is throwing exceptions
so there's no hard requirement for the body to be side-effect free, altho it's usually a bad sign if it is
the alternative is to split it out into a do-seq, which does the sanity-check/throwing exceptions
qqq: it's but looping twice, for is not a loop, but it is building a collection you might not need.
In my Luminus app I have a HugSQL query which returns 116 rows. If I append LIMIT 120, for the sake of argument, it runs fine (but slower than Rails) but if I remove the LIMIT clause it produces an out of memory error. Any ideas?
I increased the available memory with Xmx=4g on my dev machine but it still produces the same memory error.
I am not super familiar with hugsql, is there someway you can see the actual query it is sending?
ok, but can you, either on the clojure side, or the postgres side, log the query and compare it to what you think it should be?
hiredman: I don’t know of any process within Luminus which displays the sql as, for example, in Rails console
hiredman: I suspect it’s some kind of lazy evaluation issue but it’s a puzzle as to how it works with a LIMIT clause appended. No Luminus errors so the code is clean.
nah, I bet the actual query being run isn't what you think it is, for whatever reason
I suppose, it could also be hugsql trying to be smart about paginating results, and failing horribly at it, which you would see evidence of in query log, lots identical queries flooding in
is there a good ring middleware that will convert the keys of incoming json requests to use dashes instead of underscores?
@hiredman hugsql doesn’t generate sql. It uses raw queries and just maps them to clojure functions
which I use to generate query strings...that I call with raw java.jdbc
@U236LQYB0 isn't it a bit beta?
you ask that because of it being version 0.8.2
, or for some other reason?
Oh, I was confusing it with hugsql which was mentioned above outside of this thread. Will be taking a good look now, thanks!
I tend to use https://github.com/tomekw/hikari-cp , which as examples on how to use with clojure, but you can also use bonecp or c3p0 if you have more experience with them or personal preferences, I've never seen much of a difference
the functions from honeysql just allow you to compose SQL query strings, which you then use directly with clojure.java.jdbc. So there's no actual interaction between honeysql and hikari-cp, just interaction between hikari-cp and clojure.java.jdbc, which play nicely together
thanks, would you call this a production-ready stack? looks like honeysql is a clean "query builder" api which is easy to work and debug with. no crazy abstraction concepts.
I've used it in production stacks
without issues
so yes, from personal experience, I'd say it's a production ready stack
for the note, if you use postgres, then you should check out https://github.com/nilenso/honeysql-postgres which adds some additional functionality for postgres specific features (like, insert into ... on conflict ...
)
honeysql works well with mysql as well, but there is some lack of built in features for doing mysql's specific stuff, like insert into ... on duplicate key
hikari & jdbc are fine with mysql
for the cases where you do need to do something that honeysql doesn't support (which tends to be somewhat rare), I tend to just fall back to writing the SQL queries manually, but it's not overly difficult to extend
I might also look for low hanging fruit that creates a database definition script from an existing database... just in case you've seen anything like it in the clojure world (in the Scala cosmos there's a library for that). Otherwise, I'll just use mysql workbench..
which scala library are you referring to?
a simple export script can be created with custom (clojure agnostic) tools and run as a script on deploy, no need for a clojure thing for that..
that's what I generally do; a pg_dump --schema-only
or similar mysqldump
command
@benbot thanks, I will look into korma. hugSQL looks a bit raw to me though. maybe just my false impression.
I have the sense that many folk avoid korma now, being too macro-oriented. I myself prefer honeysql, as does the author of clojure.java.jdbc, incidentally
Interestingly, the most recommended clojure.java.jdbc is at version "0.7.0-alpha3". Not sure what to make of it..
@U1YTUBH53 all of the versions post 0.6.1
(which are "coincidentally" all marked alpha) are targeting the yet to be released clojure 1.9; they should be stable-ish, but they are being built for a version of clojure that hasn't had a stable release yet
not any firm release dates, no
well, the integration of honeysql and clojure.java.jdbc
has not been straightforward for me. It looks like clojure.java.jdbc
(the default/recommended choice for hickari-cp?) has its own DSL for inserts, rendering query building with honeysql superfluous. Or I've not picked the right function from the source of it.
I was hoping something like:
(let [insert (-> (insert-into :sessions)
(values [{:text message
:is_user true
:time 3
:session_id 3}]))]
(jdbc/with-db-connection [conn {:datasource datasource}]
(jdbc/insert! conn insert)))
But insert!
expects a table name and row data, not a ready-made sql statement coming from honeysql
Also for performance sake, I'd like to use prepared statements, any sample code (honeysql + clojure.java.jdbc with hickari-cp) will be appreciated
once you call honeysql/format
, you get a result that looks like [query-string args]
, this is exactly the form that clojure.java.jdbc/query
takes; so you can take your example from above and add at the end of the ->
threading a call to honeysql's format
, and then change jdbc/insert!
to jdbc/query
Use jdbc/execute!
for arbitrary commands
FWIW the insert situation is mildly incongruous; it’s one place where clojure.java.jdbc
dips its toes into sql generation
I think I've found a bug in clj-http. Just want to run it past the channel here before I go to the trouble of reporting it. Basically, if I try to send a request with :form-params {"foo[]" ["foo1" "foo2"]}
, the "foo[]" param is dropped from the request.
Seems like we must have a middleware that is interfering somehow, or something. I can't reproduce the issue. https://gist.github.com/DanBurton/4f27863b57b957d86cc9a1b77a5ba645
I take it back. I know what the bug is now. It happens when we use :method :delete
. It seems to ignore :form-params
for this method.
According to someone on the internet > The latest update to the HTTP 1.1 spec explicitly permits entity body in DELETE request. ~ http://stackoverflow.com/a/10015724/208257
Issue submitted https://github.com/dakrone/clj-http/issues/365
I have a weird issue with Manifold in my project. Some other dependency must cause the weirdness, because from a fresh project I don’t get this issue: https://gist.github.com/borkdude/62bbdb76834388023a6dffbd0023f4cd
hi. will AOT in java9 speed up loading Clojure libs? it says, invoked dynamic is not yet supported http://openjdk.java.net/jeps/295
Toby Crawley gave a great talk about Java 9 and what it means for Clojure at Clojure/West this year: https://www.youtube.com/watch?v=4fevIDAxQAM&list=PLZdCLR02grLp4W4ySd1sHPOsK83gvqBQp&index=15
@andmed the best resource to find out what java 9 does is probably the stuff from toby crawley, including his talk at clojure/west a couple of weeks ago, which is on youtube (that I see @seancorfield just posted) and he has resources on this github repo https://github.com/tobias/clojure-java-9
i see in presentation it does not help a lot in absolute numbers, so not a deal breaker
the main issue with startup time for actual day to day usage is usually leiningen (if you use it) and nrepl (if you use it) - clojure.jar is pretty fast (and loads libraries pretty fast, but that depends on the specific lib of course)
oh, I recall I have seen somewhere on the net, detailed profiling of what takes what to load a clojure core, I guess JIT was not the main issue
x$ time java -jar ~/bin/clojure-1.9.0-alpha15.jar -e '(println "hello, world!")'
hello, world!
real 0m1.234s
user 0m1.728s
sys 0m0.152s
not great, but not terribleyou can feed the output chan from one pipeline-blocking as the input chan to another, if that’s what you mean
@noisesmith i mean something like this (pipeline-blocking to 12 (map #(pipeline-blockings to1 12 (map somefnc) %)) from)
because in from
channel i have a vectore of sources, which i need to make a request to each one , then
a remote service will return several articles, and i have to request for details of each article again