Fork me on GitHub
#clojure
<
2016-10-28
>
pupeno00:10:38

Is it possible to write a schema that validates more than one field at a time together?

idiomancy01:10:48

anyone know of a x-www-form-urlencoded parser or x-www-form-urlencoded to edn converter?

gfredericks01:10:01

idiomancy: I'm sure the ring libraries use one somehow

idiomancy01:10:56

ahh, good place to look

bfabry05:10:08

I often feel like a macro

(in-parallel
  (external-api-call)
  (external-api-call)
  (external-api-call))

bfabry05:10:10

would be useful

bfabry05:10:18

am I missing something in core that's already this?

bfabry05:10:35

the way I usually do it is (run! deref [(future (api call)) (future (api call))])

baptiste-from-paris06:10:26

@bfabry you might want to use go process to put and retrieve the result

bfabry06:10:50

@baptiste-from-paris I mean, I could make each of those future calls a go block but that's doesn't really gain me anything as far as I can tell

baptiste-from-paris06:10:28

i really depends whether you need to deref it or not

baptiste-from-paris06:10:42

base on you use case, it depends

bfabry06:10:47

I don't, but I do want to "block until all the background tasks are done"

bfabry06:10:04

which is what my run! example does

baptiste-from-paris06:10:09

why do you need to block everything

bfabry06:10:21

because the next task I want to execute depends on all of those tasks having completed

thedavidmeister09:10:05

hey, is this the right channel to ask about namespace tools and cljc?

urbanslug12:10:19

Say I have a vecor of maps, is there an easy way to run through each map and get the values of a specific key?

urbanslug12:10:46

[{:a :c} {:a :b} {:a :z}]

urbanslug12:10:58

to get [:c :b :z]

henriklundahl12:10:33

@urbanslug (mapv :a [{:a :c} {:a :b} {:a :z}])

dominicm12:10:42

Probably better to do it lazily though ^^ just in case.

matan12:10:27

Just wondering, is there anything in or for Leiningen, that can re-run your project whenever you save any of its sources? (like figwheel for clojurescript, nodemon for node.js, etc...)

jfntn12:10:45

I have this issue where loading my dev/user.clj is not enough to properly load the files it requires, I have to go and manually load some of the transitive dependencies, and it only errors at runtime...

jfntn12:10:18

I remember running into that in the past and never really figured out what the problem was, but my current project is plagued with those problems

dominicm13:10:50

@matan Some people use an editor hook, (e.g. for vim autocmd BufWrite *.clj Eval (reset)) but most people just map it to a short keybinding (I have a reset bound to ,rs for example)

dominicm13:10:04

@jfntn That kinda sounds like the namespaces aren't being required, and are perhaps using fully-qualified namespaces in order to hack it into working?

timgilbert14:10:21

@matan: depending on your application, there tend to be some tools around this too; for example for Ring apps there's the (wrap-reload) function: https://ring-clojure.github.io/ring/ring.middleware.reload.html

dominicm14:10:57

@timgilbert wrap-reload doesn't work with stateful things particularly well.

timgilbert14:10:42

Well, I agree in principle but for less stateful things it's more handy than needing to restart your web server every time you make a code change...

danboykis14:10:32

@matan you can see an example app with restartable web server here: https://github.com/tolitius/stater/tree/master/smsio

danboykis14:10:53

to restart the server (only that component) for example, you'd do:

(mount/stop #'app.www/web-server)
(mount/start #'app.www/web-server)

matan15:10:55

Thanks a lot. I was actually, admittedly, looking for something easy rather than simple 🙂 as in the Scala world this was built into the equivalent of leiningen. I think I'll avoid the need for code changes and skip on this dev flow feature for now...

dominicm16:10:07

@matan It's not common to restart the entire server in Clojure, it's considered too slow of a process.

matan16:10:09

Yeah well I'm writing small services, not a server

matan16:10:32

E.g. data transformation services

dominicm16:10:43

If you're completely stateless clojure.tools.namespace.repl/refresh-all should work if you depend on tools.namespace

bja19:10:44

I don't suppose there's anyone else here crazy enough to try to interoperate jython and clojure?

bja19:10:54

running into a problem with jython not being able to figure out MRO for clojure.lang.PersistentVector's remove(), and was hoping to find someone else who has encountered the issue

nickmbailey19:10:21

i run jython and clojure together

nickmbailey19:10:27

haven’t encountered that issue though

nickmbailey19:10:49

can you describe the issue more?

bja19:10:50

it's actually pretty easy to duplicate. if you take a recent Jython standalone jar (grabbing 2.7.0 from their homepage), add clojure-1.8.0.jar to the classpath and run

java -cp jython-standalone-2.7.0.jar:clojure-1.8.0/clojure-1.8.0.jar org.python.util.jython -c "import clojure.lang.PersistentVector"

bja19:10:22

Traceback (most recent call last):
  File "<string>", line 1, in <module>
TypeError: Supertypes that share a modified attribute have an MRO conflict[attribute=remove, supertypes=[<type 'clojure.lang.ASeq'>, <type 'java.util.List'>], type=APersistentVector$RSeq]

nickmbailey19:10:02

yeah we have a shim that converts all our clojure-y stuff to jython-y stuff

bja19:10:15

yeah, I can do that

nickmbailey19:10:25

i actually have it in a gist

bja19:10:40

ooh, thanks

nickmbailey19:10:05

been meaning to put it in its own repo and ‘publish’ it but haven’t gotten around to it

nickmbailey19:10:44

i’m now vaguely remembering those MRO errors and i don’t think we ever came up with a different solution besides converting to jython objects first

nickmbailey19:10:53

something to do with multiple inheritance

amacdougall20:10:17

Huh, this is surprising... I can't use a namespaced keyword which is the same as a function name? In other words:

(ns foo)

(defn bar [x y]
  {::bar (+ x y), ::other-stuff [...]})

(ns baz
  (:require [foo :as f]))

(defn get-bar []
  (::f/bar (f/bar 1 2)))
The get-bar function will complain that #'foo/bar is not public, even though the invocation of ::f/bar would seem to indicate that I'm referring to the namespaced keyword, not the function.

amacdougall20:10:28

In practice, I can avoid this kind of overlap, but it's surprising that it's an issue.

josh.freckleton22:10:19

How can I refer required vars/fns as something else? IE (require [core.x :refer [map :as x-map, reduce :as x-reduce]])

josh.freckleton22:10:36

to avoid name collisions?

arrdem23:10:07

@josh.freckleton (:require [core.x :refer :all :rename {map x-map, reduce x-reduce}]) which is HIGHLY discouraged.

arrdem23:10:19

please use qualified imports instead.

arrdem23:10:37

Eg. (ns ... (:require [core.x :as x] ...)) ... x/foo

jrheard23:10:34

i think that last line is meant to be :require rather than :refer

jrheard23:10:52

unless i’m mistaken

arrdem23:10:26

Yep. Fixed.