Fork me on GitHub
#clojure
<
2019-04-06
>
noisesmith00:04:26

if you dissoc x, it downgrades to a hash-map, last I checked

Dustin Getz00:04:52

Yeah, so (defrecord [mandatory-id]…) and then we good

souenzzo01:04:35

When I start #datomic -ions + #shadow-cljs in the same repl, my JVM just freezes. How can I debug this? I think that I'm running out of threads

thheller10:04:00

which platform does that run on? JVM can take quite a few threads so its unlikely you are running out?

souenzzo12:04:23

It's a [email protected] I'm using a i7 so there is 8vcpu. When jvm freeze, it keep at "0%" of cpu usage. When I query first, the start shadow, it keep compiling forever (web UI works, but do nothing about stop/start builds ) When I start shadow first, then query, the query freezes / lock my repl

thheller12:04:20

can you be a bit more detailed and tell me what code exactly you execute?

thheller12:04:49

I have basically never seen a JVM freeze so that sounds very weird to me

thheller12:04:23

but in general: why are you running shadow-cljs as part of a datomic ion? that makes little sense to me?

souenzzo12:04:29

It's just my dev setup. I like to keep everything in one repl. At home I will try to make something reproducible

noisesmith17:04:22

if you use Control-\ or use jstack you can trigger a dump of the stack traces of all running threads. My hunch is that something is running and not getting expected input.

eccentric J14:04:41

I could use a little help designing an algorithm. How would you go about transforming between the two formats?

{:logger {:name :logger
          :deps [:render]}
 :render {:name :render
          :deps [:store]}
 :store {:name :store
         :deps [:router]}
 :router {:name :router
          :deps []}}

;; Would like to format as:

[[:router []]
 [:store  [:router]]
 [:render [:store]]
 [:logger [:render]]]

eccentric J14:04:40

I implemented a gross solution in JS by first transforming the input into {:router {:store {:render {:logger {}}}}} then walking it again to build a list like the bottom. However, I feel like I’m making it messier\more complicated than it needs to be.

valtteri14:04:13

(reduce-kv (fn [res k v] (conj res [k (:deps v)])) [] input-map)

valtteri14:04:59

(mapv (fn [[k v]] [k (:deps v)]) input-map)

valtteri14:04:47

(mapv (juxt first (comp :deps second)) input-map)

leonoel14:04:00

this doesn't give the right order @U6N4HSMFW

valtteri14:04:33

Ahh, order matters?

leonoel14:04:09

I guess so, but can't speak for the OP

leonoel14:04:31

the problem being solved here is topological sorting

valtteri15:04:00

Ahhh, I thought it was simply transforming data format to another, which is quite trivial though. It’s likely that I didn’t get the point from the example. 🙂

valtteri15:04:43

But yeah, now looking at it it makes sense. I’d maybe look how integrant or component does that.

leonoel15:04:06

the algorithm is not very complex so it's not rare too see ad-hoc implementations in libraries having to do some kind of dependency resolution

eccentric J15:04:52

Oops sorry for not being clear but yes, order does matter.

eccentric J15:04:17

Thanks for the help, finding out the name of the algo for it is a ton of help!

noisesmith17:04:05

If it helps, this is very close to being an adjacency-list / tree transform, which is well studied and well documented. And loom itself has code that turns a tree into an adjacency list and visa versa (every tree can be converted to an adjacency list, an adjacency list can only be converted to a tree if its graph is non-cyclical, directed, and each node has only one incoming link)

eccentric J18:04:11

Thanks @U051SS2EU. Learning the term helped me find a section about it in an algorithms text book I impulsively bought but never used. After reading that section then watching a youtube talk on topological sorting I was able to implement a depth-first-search topological sort for directed-acyclic-graphs on my own 😄

noisesmith18:04:59

adjacency-lists are especially useful in a language with immutable data structures, as they allow cycles and complex nested updates without doing a tree worth of mutations

eccentric J18:04:27

Ah that makes sense, the book’s solution used an AdjacencyList but it also used a mutable list to track what was visited. I’m not quite sure how to handle that part in an immutable language without something like an atom.

eccentric J18:04:12

Actually I take that back. The recursive function would need to return the updated sorted list and the updated visited list is all.

noisesmith19:04:21

precisely - we can use normal updating / recursion tricks, and it's simplified since it's flattened

piyer14:04:28

I am using the https://github.com/metosin/compojure-api/wiki/Component-integration#using-closures but how does this work in development env? In the case of defroutes it is a var and evaling(c-x c-e) changes just works. In the case of closure, I have to keep restarting the server.

schmidt7315:04:14

@munichlinux Component out-of-the-box needs a little setup to have it work well in a hot-reloading environment. I'm assuming you're using CIDER + Emacs, my setup defines reloading functionality for component called user/reset in dev/user.clj. Then I have key chord C-x C-r setup to call user/reset, which refreshes component. It works perfectly. For example, I could define some new functionality for a closure, test it with C-x C-e, and then hit C-x C-r to see the changes appear.

schmidt7315:04:51

@munichlinux This isn't my own idea it's based off the article: http://thinkrelevance.com/blog/2013/06/04/clojure-workflow-reloaded. Though the article won't get you all the way, if you follow through it and tinker with your emacs config for a bit, you'll be able to find a good solution. If you want to check out my .emacs config file I can send it over in a private message.

piyer15:04:47

@henri.schmidt Thanks for the link

piyer15:04:55

I doing the same thing. I though there could be a better way since I have to keep firing (reset) all the time.

schmidt7315:04:16

@munichlinux yeah I hoped as well, if you find one message me about it. Though I think it's unsolvable due to components use of protocols.

schmidt7315:04:37

Here's my elisp code for resetting component.

schmidt7316:04:12

@munichlinux so this will save and refresh component every time you reset buffer?

schmidt7316:04:16

Thank you for the link.

schmidt7316:04:34

Also what happens when there are errors in the saved buffer?

piyer16:04:19

@henri.schmidt you can turn the logger on *cider-ns-refresh-log*

piyer17:04:22

now I change my code, do C-M-r, that does the magic.

Wes Hall18:04:28

Is it possible to compose aliases in deps.edn? For example, if my ~/.clojure/deps.edn contains a test alias (adding test directory to the path) and a cider alias (adding some cider libs), can I create a dev alias in my main project deps.edn which says, "switch on the test and cider aliases when dev is used"?

lilactown18:04:20

I don’t believe so

lilactown18:04:45

you can add them both in the args. e.g. -A:test:cider

lilactown18:04:51

but you can’t create aggregates

lilactown18:04:29

that would combine them by name like -A:test-cider like you’re saying

Wes Hall18:04:38

Ok, thanks. What I was really trying to do here was to configure cider to start with the dev alias by setting cider-clojure-cli-global-options to -A:dev and then configure the dev profile on a per project basis. I suppose I can either just put all of the config in the project dev alias (little duplication, but nothing too worry too much about), or get into .dir-locals.el stuff, though emacs seems to complain about setting this the cider-clojure-cli-global-options variable in dir locals. Apparently it "may not be safe", but I am not sure exactly what determines that. Probably simpler to do the first thing I suppose.

lilactown18:04:27

yeah. it’s super annoying to set those options right now in CIDER

lilactown18:04:32

we should open up a ticket

lilactown18:04:43

I hate that message that pops up everytime I open a new file 😧

Wes Hall18:04:05

It does seem to give me an option to say, "Mark this variable as safe in the future", but I am not sure I understand why it is unsafe. Something makes me anxious about overriding a message like this without fully understanding it 🙂

lilactown18:04:31

one of the things I’ve noticed is sometimes those settings bleed between projects

Wes Hall18:04:59

Ahhh... yeah, that would be a little unsafe I guess 🙂

dpsutton19:04:52

If you cider jack in with a prefix argument you can edit the actual startup form. Makes it easy to tweak those without knowing which config to set

lilactown19:04:27

I just want to SPC m ' and not think about it 🙃

ivana20:04:23

Hello. I want to present you yet another nobody needed Clojure gebugging library 🙂 Which channel would be right for it?

orestis20:04:50

#announcements ?

ivana20:04:01

maybe, I'm not sure. thanks, I'l post it there