Fork me on GitHub
#clojure
<
2017-04-13
>
noisesmith00:04:12

in fact, if you treat the two source bodies as a merge conflict, it should write itself haha

lsenta02:04:53

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?

momofarm02:04:06

could someone explain this binding https://clojuredocs.org/clojure.core/binding in a more simple way?

momofarm02:04:42

I'm trying to do things like (not-any? (binding (string/includes? xxx) yyyy)) but don't know / not sure how to bind it

noisesmith02:04:57

what do you actually want binding to do?

noisesmith02:04:32

it's like let, but it replaces variables that have been marked :dynamic inside a specific scope for only one thread

noisesmith02:04:20

if string/includes? doesn't exist, and isn't dynamic, that code will never work

momofarm03:04:04

so i need to declare something dynamic to allow bind replace it?

noisesmith03:04:21

right - or someone does

noisesmith03:04:42

and it needs a vector (like let, or anything else in clojure that creates bindings)

noisesmith03:04:03

(binding [*foo* some-other-thing] (code-that-uses-foo ...))

noisesmith03:04:29

which brings me back to the initial question of what you are trying to do

momofarm03:04:38

i have an array of string, I'm trying to find the occurance of one or more match of specified keyword

noisesmith03:04:58

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)

momofarm03:04:27

i can't understand what's "#(string/includes? % "...") " for......it that a predicate?

momofarm03:04:53

I must miss something in the quick intro......

noisesmith03:04:12

it's a shorthand for fn

noisesmith03:04:45

(fn [s] (string/includes? s "..."))

momofarm03:04:55

ohoh i got it

momofarm03:04:37

is there a more comphrensive guide that I can read all these common use ways to use clojure?

noisesmith03:04:20

clojure for the brave and true is popular, there's also aphyr's clojure from the ground up http://www.braveclojure.com/

momofarm03:04:22

ok thanks a lot

samumbach03:04:04

@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

lvh04:04:58

@U050WMHUV hey! Yeah, clojure loads this conditionally on jdk 8 so you can't remove that file :)

samumbach13:04:24

I didn't remove this file; I have no idea why I see this error when switching from clojure 1.8 to 1.9

samumbach13:04:32

thanks for getting back to me 🙂

samumbach13:04:07

I'm going to put my clojure 1.9 upgrade on hold for the moment...

lvh12:04:56

the file got added in 1.9; it seems like something is probably getting rid of it for you. Are you building uberjars?

seancorfield03:04:51

@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.

momofarm03:04:05

@seancorfield thanks! i just start to use it few days ago, indeed i do need some help

samumbach03:04:28

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)

martinklepsch06:04:18

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?

clojureman10:04:24

(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”

dominicm10:04:09

@U050TNB9F mustache? 😄

martinklepsch18:04:12

@U2BTBFQVC oh, that’s a nice and simple solution, I wasn’t aware you can provide a function as replacement, thanks!

clojureman18:04:26

Yes, the terseness of Clojure can be quite addictive 😀

martinklepsch06:04:49

Maybe Mustache is what I’m looking for?

martinklepsch06:04:00

@delaguardo it would get the job done but I’d prefer passing the named things as data instead of local bindings

sreenath.n06:04:48

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.

bronsa08:04:18

that doesn't make much sense as load doesn't act on namespaces but on files

bronsa08:04:48

also it's normal for functions that side-effect to return nil

bronsa08:04:08

what about it?

sreenath.n14:04:44

@U060FKQPN , makes sense. So, How can I know which namespaces are defined in the file which I just loaded using "clojure.core/load"?

bronsa14:04:42

nothing says that a file loaded even defines a namespace at all

sreenath.n14:04:08

@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.

bronsa14:04:40

yes but tools.namespace makes some very specific assumptions which usually don't hold for files that you load through load

sreenath.n14:04:25

Let me take a step back, when is it recommended to use load? what are difference you were referring to?

bronsa14:04:12

you almost never want to use load

danielstockton07:04:01

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

thandogqwabaza07:04:42

@andrea.crotti @jumar @slipset Thank you very much for the emacs.

jumar07:04:51

@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?

danielstockton07:04:12

lein figwheel lein repl any lein command...

danielstockton07:04:32

If I revert back to 1.8.0 everything is fine.

danielstockton07:04:05

I deleted ~/.m2 and target/ (just in case).

dominicm08:04:47

@danielstockton which jvm version are you using? (a hunch)

danielstockton08:04:07

openjdk version "1.8.0_121"

danielstockton08:04:51

Yeah, it seems to be the import statement. Is import no longer allowed?

bronsa08:04:17

no that's not the case

bronsa08:04:59

it appears that for whatever reason core_instant18.clj is being loaded in a broken ns env

danielstockton08:04:51

I tried alpha14 too and I have the same problem.

danielstockton09:04:43

: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.

ilevd09:04:59

Does anyone know something similar to https://github.com/stevenvachon/broken-link-checker written on Java/Clojure?

benbot10:04:15

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

benbot10:04:21

(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)

benbot10:04:30

where quote-to-count returned a future

benbot10:04:01

the weird thing is that (map deref futures) doesn't block and the program just finishes up before the futures are done

benbot10:04:12

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)

pesterhazy10:04:24

laziness? try (mapv deref futures)

pesterhazy10:04:20

additionally wouldn't you want to return the dereffed values, rather than quotes?

genec11:04:19

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?

genec11:04:47

just looking for a blog post, example pro, something to help me get started

dm312:04:34

@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

benbot12:04:14

@pesterhazy yeah that was in there mainly for testing.

benbot12:04:58

@dm3 I'm going through a tutorial so I'm trying to stick with the limitations they gave me :/ raw clojure and futures

benbot12:04:15

Fixed it by wrapping the map call in a 'doall'

noisesmith16:04:28

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

john13:04:02

@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

genec16:04:45

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.

john01:04:55

No prob!

john01:04:51

Datascript is supposed to be a pretty good datomic clone for the client (cljs)

john01:04:06

Haven't messed with it

john13:04:37

but tooling is always evolving, so best practices around project structure is a moving target.

john13:04:29

like now that boot is around, in addition to leiningen, you'll likely see some very different project structures.

benbot13:04:28

I think boot and lein share directory structures… neither of them care about it I don’t think

qqq14:04:06

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 ?

bronsa14:04:02

like most lazy operations there's no guarantee that laziness will be one-at-a-time

bronsa14:04:08

but it won't be invoked twice

qqq14:04:50

alright, so I consume the entire list and (2) the only non-pure part is throwing exceptions

bronsa14:04:53

so there's no hard requirement for the body to be side-effect free, altho it's usually a bad sign if it is

qqq14:04:54

so I think I'm safe here

qqq14:04:20

the alternative is to split it out into a do-seq, which does the sanity-check/throwing exceptions

qqq14:04:28

but that seems unnecessairly looping twice

noisesmith15:04:57

qqq: it's but looping twice, for is not a loop, but it is building a collection you might not need.

clojer16:04:56

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?

clojer16:04:44

I increased the available memory with Xmx=4g on my dev machine but it still produces the same memory error.

hiredman16:04:49

what is it doing when it produces the out of memory error?

hiredman16:04:10

how do you know the query returns 116 rows?

clojer16:04:28

:jvm-opts [“-Xmx4g”]

clojer16:04:14

hiredman: I checked the sql query in Postgres.

hiredman16:04:35

I am not super familiar with hugsql, is there someway you can see the actual query it is sending?

clojer16:04:52

hiredman: It populates a Selmer template

hiredman16:04:39

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?

clojer16:04:04

hiredman: I don’t know of any process within Luminus which displays the sql as, for example, in Rails console

clojer16:04:12

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.

hiredman16:04:22

nah, I bet the actual query being run isn't what you think it is, for whatever reason

hiredman16:04:36

so you are getting a ton of results back, so oom

clojer16:04:04

hiredman: I’ll see if HugSQL has anything for debugging.

hiredman16:04:46

postgres must have some kind of query logging thing too

hiredman16:04:20

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

clojer16:04:22

hiredman: It’s definitely a single query but with a few conditional params

hiredman16:04:42

have you restarted your repl since you started seeing this?

clojer16:04:31

hiredman: Found the postgres log. It’s an sql problem 😞

hiredman16:04:22

as in the hugsql generated sql isn't exactly right?

clojer16:04:28

hiredman: Something wrong with the conditional params logic so a HugSQL issue

tjtolton17:04:28

is there a good ring middleware that will convert the keys of incoming json requests to use dashes instead of underscores?

benbot17:04:22

@hiredman hugsql doesn’t generate sql. It uses raw queries and just maps them to clojure functions

hiredman17:04:12

it absolutely generates sql, it just starts from a place closer to sql

benbot18:04:42

I don’t think so

matan18:04:22

for a brand new project, which sql libs would you use if not raw java.jdbc and why?

tanzoniteblack18:04:12

which I use to generate query strings...that I call with raw java.jdbc

matan18:04:10

@U236LQYB0 isn't it a bit beta?

tanzoniteblack18:04:51

you ask that because of it being version 0.8.2, or for some other reason?

matan18:04:59

what about connection pooling and stuff?

matan18:04:40

Oh, I was confusing it with hugsql which was mentioned above outside of this thread. Will be taking a good look now, thanks!

tanzoniteblack18:04:45

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

matan18:04:43

so you in your setup hikari-cp and honeysql play well together?

matan18:04:13

outside of clojure, hikari-cp is kind of my favorite

tanzoniteblack18:04:57

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

matan18:04:49

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.

tanzoniteblack18:04:11

I've used it in production stacks

tanzoniteblack18:04:40

so yes, from personal experience, I'd say it's a production ready stack

matan18:04:57

well thanks a lot!

tanzoniteblack18:04:23

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 ...)

matan18:04:13

I think I'll be using MySQL Any experience with that?

matan18:04:05

Well I guess a silly question, hikari can well handle it regardless of honeysql....

tanzoniteblack18:04:38

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

tanzoniteblack18:04:47

hikari & jdbc are fine with mysql

tanzoniteblack18:04:24

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

matan19:04:10

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..

matan19:04:46

Anyway, thanks again 🙂

tanzoniteblack19:04:56

which scala library are you referring to?

matan19:04:50

oh, it was part of slick. a horrendous abstraction. I'd rather forget.

matan19:04:48

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..

tanzoniteblack19:04:18

that's what I generally do; a pg_dump --schema-only or similar mysqldump command

benbot19:04:10

If you like DSLs I think korma is the most popular

benbot19:04:25

but hugSQL is pretty good imo

matan19:04:34

@benbot thanks, I will look into korma. hugSQL looks a bit raw to me though. maybe just my false impression.

donaldball20:04:02

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

matan21:04:02

Interestingly, the most recommended clojure.java.jdbc is at version "0.7.0-alpha3". Not sure what to make of it..

tanzoniteblack21:04:09

@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

matan22:04:55

any timeline for 1.9?

tanzoniteblack22:04:27

not any firm release dates, no

matan07:04:04

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.

matan07:04:15

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)))

matan07:04:49

But insert! expects a table name and row data, not a ready-made sql statement coming from honeysql

matan07:04:48

Also for performance sake, I'd like to use prepared statements, any sample code (honeysql + clojure.java.jdbc with hickari-cp) will be appreciated

tanzoniteblack14:04:16

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

donaldball14:04:42

Use jdbc/execute! for arbitrary commands

donaldball14:04:16

FWIW the insert situation is mildly incongruous; it’s one place where clojure.java.jdbc dips its toes into sql generation

danburton18:04:59

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.

danburton18:04:38

I presume this is due to the square brackets in the param name

danburton19:04:39

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

danburton20:04:05

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.

mattsfrey20:04:58

yeah delete cannot have a body

danburton20:04:11

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

xiongtx21:04:59

I’m just a total stranger, but why don’t you submit a PR to clj-http?

borkdude20:04:37

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

andmed21:04:36

hi. will AOT in java9 speed up loading Clojure libs? it says, invoked dynamic is not yet supported http://openjdk.java.net/jeps/295

seancorfield21:04:14

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&amp;list=PLZdCLR02grLp4W4ySd1sHPOsK83gvqBQp&amp;index=15

dominicm21:04:03

tl;dr stuff is gonna break a bit 😛

noisesmith21:04:45

@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

andmed21:04:32

i see in presentation it does not help a lot in absolute numbers, so not a deal breaker

noisesmith21:04:32

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)

andmed21:04:47

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

noisesmith21:04:02

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 terrible

lxsameer21:04:21

is it possible to have nested core.async.pipelines-blocking ?

noisesmith21:04:23

you can feed the output chan from one pipeline-blocking as the input chan to another, if that’s what you mean

hiredman21:04:27

what do you mean by nesting?

lxsameer21:04:34

@noisesmith i mean something like this (pipeline-blocking to 12 (map #(pipeline-blockings to1 12 (map somefnc) %)) from)

hiredman21:04:13

why would you do that?

lxsameer21:04:06

because in from channel i have a vectore of sources, which i need to make a request to each one , then

hiredman21:04:31

(comp cat (map ...))

lxsameer21:04:42

a remote service will return several articles, and i have to request for details of each article again

hiredman21:04:03

you can nest pipelines, but the kind of system that builds is pretty much something you never want

lxsameer21:04:21

that's the answer i'm looking for,

lxsameer21:04:48

@hiredman how should i solve my problem using core async?

hiredman21:04:01

use the cat transducer

lxsameer21:04:20

let me try that

hiredman21:04:30

(comp cat (map somefunc)) I may have the order the wrong way around

lxsameer21:04:05

@hiredman worked like a charm

qqq23:04:24

in spec, how do I say "keyword?" or nil

hiredman23:04:13

(s/nilable keyword?) is the efficient way

qqq23:04:28

I see, this is better than (s/or nil? keyword?) ?