Fork me on GitHub
#clojure
<
2018-11-12
>
jwhitlark08:11:26

As far as query capability is concerned, is there any reason to choose core.logic over datomic for (what I believe) is a constraint logic problem? I'm familiar with both, expert in neither, and I'm trying to figure out when I'd prefer one query model over the other.

didibus03:11:03

Datomic is a whole database, that you need to host and operate or pay for in the cloud. I'd say if all you want is a constraint engine then core.logic is what you want. If you're also looking to persist state, then datomic is what you want.

sapo09:11:42

hi all! I'm a computer engineer and I'm interested in Clojure because of the overtone framework, which seems very good. I'm having troubles in setting up Clojure with Vim. I set up a new project with lein new test. Then cd test and lein repl. I open vim src/test/core.clj from another terminal. I want to use Repl and auto formatting, but I get "FileNotFoundException Could not locate test/core__init.class or test/core.clj on classpath. clojure.lang.RT.load (RT.java:463)". My (Neo)Vim configuration looks like this.

jsa-aerial16:11:12

There is a #vim channel that may be more useful for you. Also there is #beginners

Vincent Cantin11:11:08

I just met a strange behavior in the Clojure repl: :3d is accepted as a keyword, but :aoeu/3d is not. Bug or feature? RuntimeException Invalid token: :aoeu/3d clojure.lang.Util.runtimeException (Util.java:221)

pkova11:11:10

keywords starting with numeric characters will work, and even (keyword "hello there") will work, but should be avoided

Vincent Cantin12:11:13

So the bug looks like :3d being accepted.

Alex Miller (Clojure team)17:11:03

there’s a lot of history on this but we have grand-fathered in keywords that start with a number

emil0r15:11:51

is it possible to have multiple implementations of a multimethod for the same dispatch value? ie, i want to catch :foo/bar as a dispatch value in more than one place and handle it differently for each implementation

schmee15:11:44

if you want different dispatch, why not have different values?

schmee15:11:25

if that’s not possible, there is nothing stopping you from having a cond in your multimethod and do more dispatch there, but that kind of defeats the purpose of multimethods

thomash15:11:26

I believe he wants to provide different implementations in different namespaces, such that the "local" or "closest" implementation will be used.

thomash15:11:16

This way, a new namespace could come with its own implementation of a specific method.

schmee15:11:28

ahh, that makes sense

emil0r16:11:15

what @the is saying, with one caveat. I want both to run 🙂

emil0r16:11:03

oh well… i guess i need to refactor

emccue16:11:38

@emil0r Refactor, or make a macro

emccue16:11:30

its probably buggy because it involves mutable-state, buuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuut

emccue16:11:40

(give me a few minutes to hack something out

emccue17:11:44

(something something global hashmap, taking longer than I thought)

emccue17:11:46

(okay I give up in shame)

thomash18:11:02

I made a quick test in the repl, and to me it looks like later implementations of the same defmethod would overwrite/shadow earlier definitions.

Alex Miller (Clojure team)18:11:51

you can only have one defmethod impl per dispatch value and last one def’ed wins

schmee18:11:48

is there a way to syntax quote a symbol, while already in a syntax quote?

schmee18:11:17

I’m trying to come up with a better example of what I’m trying to do, hold on a sec…

Alex Miller (Clojure team)18:11:48

all symbols within a syntax quote will (deeply) be resolved to qualified symbols

schmee18:11:31

I figured it out. basically, I’m used to doing

`foo
to get a namespaced variable, but that doesn’t work if you’re already in a syntax quote

Alex Miller (Clojure team)18:11:20

right, you actually just need foo

Alex Miller (Clojure team)18:11:37

syntax quote resolves all symbols inside it

schmee18:11:51

yes, but in this case the foo is passed in to the macro as a keyword, which means I have to do something like

`~(name the-keyword)
and I couldn’t figure out the right syntax for that 😄

Alex Miller (Clojure team)18:11:07

well that isolation doesn’t need to be in syntax quote at all, but I guess you figured that out

schmee18:11:26

yup 🙂 as an intellectual exercise, is it even possible to do this with the right combination of ` and ~?

schmee18:11:49

so I did (symbol (-> *ns* ns-name name) (name method)) outside of the macro and then unquoted that thing instead

schmee18:11:11

to go from a keyword to a namespaced symbol

Alex Miller (Clojure team)18:11:16

as of latest 1.10, you can just call symbol on a keyword to get the symbol

Alex Miller (Clojure team)18:11:52

although that won’t take care of resolving in the current namespace

Alex Miller (Clojure team)18:11:45

but resolve is probably preferable for that

schmee18:11:15

neat! 🙂

Alex Miller (Clojure team)18:11:34

actually, I guess that gets you to a var which is maybe not what you’re looking for

schmee18:11:36

speaking of, how does one go from a var to the namespaced symbol of the var?

Alex Miller (Clojure team)18:11:49

well, as of latest 1.10, with symbol :)

😄 8
Alex Miller (Clojure team)18:11:04

but otherwise you have to reach into the private fields of clojure.lang.Var

tvalerio18:11:44

Hi, can anybody help me with this? I have a list of maps with this structure:

({:a 1} {:b 2} {:c 3})
How could I get someting like this?
({:a 1 :b 2 :c 3})

mfikes19:11:22

One way is (list (apply merge ms))

mfikes19:11:07

Another: (list (reduce conj ms))

lisovskyvlad19:11:38

What a beauty

tvalerio19:11:06

It worked! Thanks!! 😍

mikeb19:11:04

I would like to write items to a file one a time from multiple concurrent http requests, and would like to ensure that only one write is made at a time. This would be relatively low volume, but would still like it to be efficient. What's the suggested way to handle this in clojure?

noisesmith19:11:29

a simple way to do it is a dedicated writer thread and a queue for incoming strings

Alex Miller (Clojure team)19:11:07

an agent is a simple way to cover that

mikeb20:11:51

Ok, I will look into both of those. Thanks!

noisesmith20:11:01

@alexmiller is there a good pattern for an agent "owning" an io destination and writing a series of Strings? I think the thing that trips me up is having to pass it a function that returns the new value of the agent which seems clumsy.

Alex Miller (Clojure team)20:11:23

just use nil as the value

Alex Miller (Clojure team)20:11:29

that is, don’t use one

Alex Miller (Clojure team)20:11:47

close over whatever state you need when you make the agent

noisesmith20:11:52

oh, so just using it for synchronization and not the value itself

noisesmith20:11:10

nice, I'll have to remember that trick

Alex Miller (Clojure team)20:11:14

there are some clojure loggers that do this

Alex Miller (Clojure team)20:11:28

I’ve used it for other “single writer” patterns too

mikeb20:11:21

Thanks Alex that sounds like exactly what I need.

emil0r20:11:35

hahahaha… that’s soooo messed up and cool 😄

emccue20:11:23

anyways, if you just want to stack side effects across namespaces, thisll do ya

emccue20:11:30

and now that "could" is answered, we get to the "should"

Lennart Buit20:11:12

your reasoning seems backwards

emccue20:11:00

oh it totally is

Ian Fernandez20:11:32

what happened to Lacinia channel?

manutter5120:11:01

I don’t think there was a separate Lacinia channel, just the #graphql channel

phill20:11:35

how do you run tests with deps.edn instead of project.conf?

phill20:11:44

Tried :main-opts ["-e" "(require 'clojure.test) (clojure.test/run-all-tests)"] but the result is Exception in thread "main" clojure.lang.LispReader$ReaderException: java.lang.RuntimeException: EOF while reading, starting at line 1

phill20:11:48

Tried :main-opts ["-m" "clojure.main" "-e" "(require 'clojure.test) (clojure.test/run-all-tests)"] but the result is Exception in thread "main" java.lang.NullPointerException at clojure.main$main_opt.invokeStatic(main.clj:317)

phill21:11:23

What went wrong with -e?

seancorfield21:11:03

:main-opts ["-e" "(require,'clojure.test),(clojure.test/run-all-tests)"] 

seancorfield21:11:03

Because of the way the options are processed by the shell script and written to files and then read back in by the shell script, whitespace breaks things. But because Clojure treats , as whitespace, you can work around that issue.

seancorfield21:11:47

But, yeah, as Alex suggests, look at the Cognitect test runner -- that's how we run everything at World Singles Networks these days.

phill21:11:07

Oh, the whitespace surprise is issue https://dev.clojure.org/jira/browse/TDEPS-56 .

noisesmith21:11:57

also, clojure.test isn't going to load your test namespaces, so you'd want to put them in your require or run something that knows how to find and load them

phill21:11:31

Oh yes - I used :extra-paths in the :test alias.

phill21:11:07

With,the,commas,all,is,well,except,for,the,commas

phill21:11:55

can,be,too,much,of,a,good,thing,however

phill21:11:30

I,sympathize,with,shell,escaping,escapades.

phill21:11:21

Alright I have a lib and an app that uses the lib; am converting from Leiningen to tools.deps. I used Leiningen "checkouts" to give the app a symlink to the lib so I would not have to constantly mvn install it. Can I do likewise with tools.deps? There is :classpath-overrides but I am puzzled what to set it to. For example, if I say ../lib/src then how will it find the resources?

Alex Miller (Clojure team)21:11:35

you could use :override-deps with a {:local/root … } dep instead

mpenet04:11:11

Isn't that bugged atm? I recall having to use classpath override to do this a while ago

Alex Miller (Clojure team)04:11:45

Oh shoot, I forgot that

Alex Miller (Clojure team)04:11:53

someone should fix that

Alex Miller (Clojure team)21:11:52

{:deps {my/lib {:mvn/version "1.2.3"}}
 :aliases {:dev {:override-deps {my/lib {:local/root "../lib"}}}}}

andy.fingerhut21:11:13

I,sympathize,with,but,mentally,suffer,from,some,shell,escaping,escapades.

andy.fingerhut21:11:54

I often see them as a signal to jump ship out of a shell script and use a "real" programming language.

phill21:11:28

Which is what a user of deps.edn might in fact have thought they were doing

phill21:11:45

But it's turtles all the way down, you know

andy.fingerhut21:11:10

Yes, clj and clojure are right at the boundary between shell and Clojure, and parts of them must live with lowest common denominator I guess.

phill21:11:43

Let's not make excuses

andy.fingerhut21:11:09

It isn't clear how I am trying to make an excuse there. bash is what it is, and it isn't going to change fundamentally in the next 10 years, I doubt, nor would I try to.

phill21:11:32

Oh, right. But 59 well-placed ' and " in the shell script might cure the problem

andy.fingerhut21:11:42

That sounds to me like you are agreeing you don't like shells as general purpose programming language. If so, we are in violent agreement.

phill21:11:41

By the way I found your attention to the clojure jira, over the years, very helpful to my understanding.

phill22:11:17

(bow and scrape). I presume you enjoyed it also.

andy.fingerhut22:11:26

Cool, glad it helped someone else other than me -- I fear I may have spent more time on that than was mentally healthy for one person to do 🙂

phill22:11:45

Thats for sure but maybe recovery will be possible

andy.fingerhut22:11:58

I think I am in progress on that 🙂

andy.fingerhut22:11:08

I hope your statement above does not mean you feel any need to bow and scrape to me. I certainly don't think there is.

Alex Miller (Clojure team)21:11:42

you’re depending on my/lib, but override that artifact to point to a local project

phill21:11:52

Thanks Alex

phill22:11:11

I think I need to declare an alias wholly in /.clojure/deps.edn or wholly in a project's deps.edn; settings within an alias do not merge. For example, I tried putting alias :dev with :override-deps in my /.clojure and alias :dev (same key) with :extra-paths in the project, and the override-deps did not happen.

phill22:11:51

The doc tries to explain but I evidently misunderstood its merge-with merge

Alex Miller (Clojure team)22:11:22

the merge here is the latter one (and merge replaces)

Alex Miller (Clojure team)22:11:17

that is, what you’re saying is correct, aliases do not combine across different deps.edn files, they will be replaced if the same alias is in more than one