Fork me on GitHub
#clojure
<
2022-11-11
>
jdkealy18:11:20

How could i turn:

[[{:test "OK"} [:test "OK"]],  [{:test "OK"} [:test "OK"]]]
into
[{:test "OK"} [:test "OK"] {:test "OK"} [:test "OK]]
flatten removes to many [ ]

p-himik18:11:45

apply concat

2
p-himik18:11:17

Or, if you need the result to be a vector: (into [] (mapcat identity) data).

jdkealy18:11:49

wow nice, genius

jdkealy18:11:05

i like apply concat

phronmophobic18:11:22

(into [] (mapcat identity) data) could just be (into [] cat data)

p-himik18:11:36

Yeah, was about to check and say. :) Keep forgetting about cat.

😸 2
Alex Miller (Clojure team)18:11:42

usually, the best answer is to back up one step and use mapcat instead of map

👍 2
p-himik18:11:42

Even though I am a cat person myself.

meow-cookie 1
phronmophobic18:11:34

I usually use (eduction cat data)

Drew Verlee18:11:41

Is there an automated way to move a namespace and all it's dependencies, all the way down to the deps, into another project? say we started with project "a" (which is just the name of the root folder. The file structure looks like this: • a/deps.edn • a/src/foo/other.clj, which contains:

(ns foo.other (:require [foo.util]))
Then we have two other files, the utils which has some shared code and the core ns which we want to move out to another project eventually: • a/src/foo/util.clj • a/src/foo/core.clj, which looks like this:
(ns foo.core (:require [foo.util]))
Now we want to factor our the core namespace and all it's deps into a new project b with shared resources between project a and b. Maybe this is because it needs it's own build pipeline. This factoring process would create a shared project would just contain the foo.utils • c/deps.edn • c/src/foo/utils.clj and the new project b would import it into it's b/deps.edn:
{:deps {foo/foo {:loca/root "../c" }}}
and use it in the new core namespace (which is just the moved file from project a). And the old project "a" would similarly now reference the shared library in it's deps.

plus_one 2
p-himik18:11:25

I haven't heard of such a thing, but sounds like a useful tool to have.

Drew Verlee18:11:14

Yeah. I have had to do this task a couple times, and it's very mechanical, I feel like even if some dark corners can't be resolved (more dynamic imports?) that doing 80% would be a big improvement.

elliot22:11:02

Following up on the dynamic environment round of discussion: https://clojurians.slack.com/archives/C03RZGPG3/p1667591055017239 https://www.youtube.com/watch?v=8Ab3ArE8W3s&amp;feature=youtu.be http://blog.fogus.me/2022/11/10/the-one-about-lisp-interactivity/ I’m a little unclear whether the examples are talking about “Lisp in the abstract” vs. like particular Common Lisp interpreters, vs. Clojure in reality. It seems like having a REPL is a very core part of dynamism, but it wouldn’t be “full” dynamism until the interpreter/evaluation environment was itself reflective, and presumably “1st-class” mutable at runtime. Is Clojure-in-the-JVM actually supposed to be able to do this now, or intended to be able to move towards this in the future? Or would it require a different VM/interpreter host? Curious because this is certainly a compelling vision, but unclear if this a thing that like library community people can do vs. like can only be accomplished at the core runtime level. Any thoughts appreciated!!

elliot22:11:54

(Like just as a concrete example, I know you can re-`def` vars in a namespace via a REPL, but like conventionally that’s not really how we recommend like anybody…hot reloads anything in a prod, I think? It doesn’t seem like the same level of intention/support as in the Erlang/BEAM VM for example?)

macrobartfast23:11:54

Does anyone diagram (or is forced to diagram) their Clojure projects? I think it’s uncommon because it’s something often done in Java world and proved to be a distraction/annoyance. Or maybe it’s just unnecessary work. Maybe there are other good reasons it’s not often done. But, that said, I think it’s a fun thing that helps me see what’s going on or plan a bit. Any tips/tools/approaches/warnings appreciated.

hifumi12323:11:56

For what it's worth, lein-monolith has a feature that lets you see how all of your subprojects depend on each other. But that's the only instance I can think of diagrams being made for a project. I expect anything else to be a high-level overview of some code and meant for documentation rather than planning.

macrobartfast23:11:25

Anything like that would actually be useful… thanks!

respatialized01:11:17

Diagramming relationships between functions is occasionally useful to me - diagramming relationships between stateful systems (especially stuff like databases and scheduled jobs) is pretty much always useful. And of course, anything that involves interaction certainly benefits from diagramming. I really enjoyed the book "Sketching User Experiences" - it gave me insight into how design can be supported by drawing very well at the prototyping stage. Also, IME diagramming software (omnigraffle, etc) is almost never as generative or helpful as pen and (dot grid) paper. It doesn't matter whether the diagram stays up to date; the friction of pen on paper clarifies my thoughts enough for me to move forward.

1
respatialized01:11:12

I can see how class diagrams representing relationships between Enterprise Java ™️ objects and SetterGetterFactories and the like would get tedious quickly.

macrobartfast04:11:49

This is all awesome affirmation that there’s use in this, at least in some areas… looking at the sketching user experiences book now.

devn04:11:40

My feeling is that generally diagrams are useful mostly for the people that make them

devn04:11:50

If you need to make one for an audience, I prefer just creating them by hand rather than dealing with generated output. It’s often better, even if it glosses over some minor detail

macrobartfast04:11:50

They definitely are only intended for me.

devn04:11:04

Ah, perfect!

macrobartfast04:11:22

Well, actually… that’s not completely true: me but also to share with you all so that you can quickly scan my plan and suggest a better one.

devn04:11:22

Whatever you like wins :)

macrobartfast04:11:17

Actually, the latter is a bigger reason… but I’m sure as I sketch out my approach I’ll realize a lot.

devn04:11:20

Diagrams in my experience are often half truths. You could get validation from someone here, but whether it’s a good solution for the business and its goals winds up being a different argument altogether.

macrobartfast04:11:16

Ah, gotcha. Makes sense. My projects are so basic, though, at this point, drawings and review may be of more use. But noted.

devn04:11:35

Not discouraging them by any stretch!

macrobartfast04:11:09

I know… and you had a really good point… which is that the ‘overall picture’ isn’t really going to be represented as well as other things.

macrobartfast04:11:35

I should also probably consider pseudocode, or bodiless functions… maybe with docstrings.

devn04:11:40

Nitpicking a bit on whether or not they are in service of your goals. They certainly can be. Just depends.

👍 1
jpmonettas12:11:02

it is for creating diagrams from your source code, not before, so for documenting how a system currently works. It can also be used to statically explore how a codebase works