beginners

Getting started with Clojure/ClojureScript? Welcome! Also try: https://ask.clojure.org. Check out resources at https://gist.github.com/yogthos/be323be0361c589570a6da4ccc85f58f.
seancorfield 2021-02-08T00:00:17.197600Z

That PR does not remove the .test. part so those paths still have strange names for tooling...

yogthos 2021-02-08T00:00:18.197700Z

this is the the place https://forum.devtalk.com/tag/book-web-development-with-clojure-third-edition

yogthos 2021-02-08T00:00:30.198100Z

and makes sense

seancorfield 2021-02-08T00:09:26.198300Z

Hmm, that wasn't what I was expecting... but, yeah, that's the official forum. OK, posted a new topic about it for tracking purposes.

seancorfield 2021-02-08T00:09:49.198500Z

It seems like you'd need to change the Luminus template as well since that PR isn't quite right.

seancorfield 2021-02-08T00:10:27.198700Z

(I hadn't actually noticed that glitch when I read that section of the book -- I think my mind just auto-translated it to what I expected!)

West 2021-02-08T04:39:48.200300Z

Alright, Iโ€™m sure somebody has written about this before. figwheel-main vs. shadow-cljs โ€œWhy use one or the other?โ€ is my question.

West 2021-02-08T16:19:07.217200Z

@seancorfield Ok cool, I like how figwheel can be used with just deps.edn. @danie I didn't know about any recent npm integration like this. Where can I find more info?

danieroux 2021-02-08T16:29:08.217400Z

The new-ish integration looks like this: https://clojurescript.org/guides/webpack It works well for us.

๐Ÿ‘ 1
West 2021-02-08T05:37:08.200500Z

Seems like the main benefit to shadow-cljs is easier integration of npm dependencies and having more advanced build stages. Figwheel-main is pretty clean and easy to set up, but that's about it. Seems like shadow is the obvious way to go for everything, but maybe you guys know better.

seancorfield 2021-02-08T05:39:50.201300Z

When I did a little cljs a while back -- hacking on the Chlorine plugin for Atom -- it was a Shadow-cljs project and I was quite impressed by how smooth it was. When I decided to get more serious with cljs recently, and start learning re-frame, I looked at both and decided to use Figwheel because a) I wanted to use CLI/`deps.edn` and b) wanted to avoid npm if I can.

seancorfield 2021-02-08T05:40:22.201500Z

For you, right now, it's really not going to matter: they'll be close to the same for getting started.

seancorfield 2021-02-08T05:40:47.201700Z

Both #figwheel-main and #shadow-cljs have good support channels here.

pez 2021-02-08T06:36:58.203100Z

The support in #shadow-cljs is out-of-this-world awesome.

๐Ÿ‘ 1
danieroux 2021-02-08T07:54:56.203400Z

My main reason for using figwheel-main (sorry, could not resist) is that figwheel composes with ClojureScript, and as such is a purely dev concern. I get to compile my prod bundle this way, no figwheel in sight: clojure -M --main cljs.main --compile-opts common.cljs.edn --compile-opts min.cljs.edn --compile-opts prod.edn --compile โ€ฆ simple, clean, stable. Shadow does much more, and I am not convinced I want or need that much more. And with the newish :target :bundle , NPM integration ClojureScript is easy and clean too. And again, not a figwheel concern.

Klavs Klavsen 2021-02-08T12:50:45.210Z

Why can't for ( https://clojuredocs.org/clojure.core/for ) take a list also? it seems to me, it should be able to handle both vectors and lists (and I have a list I'd like to loop over ๐Ÿ™‚

Timur Latypoff 2021-02-08T12:52:42.210100Z

It can. Would you paste an example that does not work?

Klavs Klavsen 2021-02-08T12:53:18.210800Z

The docs just says only vector so I didn't even try ๐Ÿ˜Š

2021-02-08T12:53:31.211300Z

So far as I know, list and vector are both for-able.

Klavs Klavsen 2021-02-08T12:54:25.211500Z

Now to look for where to submit PR to improve docs then ๐Ÿ™‚

Timur Latypoff 2021-02-08T12:55:29.211700Z

@kl Ah, it means the syntax of how you write it. You pass it a "vector of binding form pairs": (for [a aaa b bbb] b) [a aaa b bbb] - is a vector of binding form pairs. aaa and bbb themselves can be any sequences, including lists.

Klavs Klavsen 2021-02-08T13:01:05.211900Z

I want to call a function that returns a list of maps (shown as ({a: 3} {a: 4}))

Klavs Klavsen 2021-02-08T13:02:29.212100Z

and do something on it IF X=Y

Klavs Klavsen 2021-02-08T13:19:41.213200Z

What would be the best way to loop over a list of maps (returned from a function) - and doing something when/if X ?

Klavs Klavsen 2021-02-08T13:20:23.213300Z

I thought for could be used.. but it seems to only want to do a let.. and since I NEED to call "remove user" - I would have no need for the let.. which seems a bit wasty/wrong then.

Timur Latypoff 2021-02-08T13:39:48.213900Z

(doseq [v (my-func) :when (= (:a v) 3)] (println v)) โ†‘ like this? The my-func returns a list of dictionaries, and we print only those which have :a 3 @kl

๐Ÿ‘ 1
Henri Schmidt 2021-02-08T13:52:21.214100Z

What do you mean by "do something"?

Henri Schmidt 2021-02-08T13:52:40.214300Z

Do you mean "transform the maps in some way, returning a sequence of transformed maps"

Henri Schmidt 2021-02-08T13:52:58.214500Z

Because if so, then I recommend using the map function.

2021-02-08T14:51:00.215Z

If you want side effects in iteration, you can use doseq, which is similar to for but intended for iterative side effects

๐Ÿ™ 1
agile_geek 2021-02-08T15:17:00.215200Z

Or run!to apply a function over each entry in a collection for side effects.

agile_geek 2021-02-08T15:18:40.215400Z

So doseqis the non-lazy equivalent of for whereas run!is like the non-lazy equivalent of map. Another option is doall but Iโ€™d prefer run!

๐Ÿ™ 1
2021-02-08T16:37:39.217600Z

@kl there are resource intensive constructs in clojure, let is not one of them. for is a lazy sequence generator (not a loop), and requires a body for generating a new output for each combination of inputs, but it sounds like you aren't trying to produce a new data structure, so don't use for

๐Ÿ™ 1
michaelteter 2021-02-08T17:36:24.219200Z

Is clojure.spec used much in real projects? (It looks very attractive to me as an outsider, and I'm thinking of making a demo to my company to entice them to try a clojure project). I wouldn't want to promote an approach that may not be "the way" things are done these days.

2021-02-08T17:40:32.219300Z

it's used, but not by everyone. IMHO the common mistakes are to treat it as if it were your type system or a coercion system. it's best at being a fail fast layer between parts of a system - like a fuse that goes off if the wrong shape of data passes through.

caumond 2021-02-08T17:54:51.219500Z

Malli is quite good also. Personnaly what I started with spec has been into malli. Easier to read and share, compose store ... apiified. Search schema malli spec to have comparaison articles.

๐Ÿ‘ 1
michaelteter 2021-02-08T17:58:26.219700Z

๐Ÿ‘Œ thanks

seancorfield 2021-02-08T18:08:44.219900Z

@michael401 We use Spec very heavily at World Singles Networks -- and have done so since it first appeared in a Clojure 1.9 prerelease build (which feels like "years" ago now). I wrote up the various ways we use it: https://corfield.org/blog/2019/09/13/using-spec/

seancorfield 2021-02-08T18:09:40.220200Z

With the caveat that there is a Spec 2.0 in development which will be quite different in some areas, Spec has proved to be very stable, solid, and useful for us, both in dev/test and in production.

West 2021-02-08T21:37:19.223700Z

Iโ€™m working on a https://gitlab.com/wildwestrom/group-creator involving graph theory. Iโ€™m trying to create an algorithm that can create groups using some given data. Itโ€™s a little complicated to explain but Iโ€™ll do my best once I start this thread.

West 2021-02-10T00:07:41.372Z

Iโ€™m not sure how I would implement a force directed graph using ubergraph.

2021-02-10T01:59:53.397Z

If you are interested in using neato, or one of the other GraphViz programs, then the problem becomes how to write the appropriate file that neato can read, and produce the graph you want. That process is probably best begun by hand-creating a small input file with 3 or 4 nodes and a few edges and running neato on it until it doesn't give syntax errors and produces a graph like you want. Then from that knowledge of what the file should look like, write a function that traverses all nodes and edges of an ubergraph data structure, printing out the correct syntax for each one to an output file.

2021-02-10T02:01:11.397200Z

or fdp or sfdp, if those produce output more like you want. Not sure if they do, but if they do, then very likely the code for printing the input file they need is probably simpler than writing code to create a force directed graph yourself.

sova-soars-the-sora 2021-02-10T04:29:22.399700Z

I think a directed graph would be enough for what I understand the problem to be -- and you could have Yes edges and Maybe edges and No edges colored differently.

West 2021-02-10T18:47:18.414400Z

I would love to have the edges be different line thickness, with the value corresponding to this function.

West 2021-02-10T19:29:55.416Z

West 2021-02-10T19:31:07.416200Z

Now my output looks like this

West 2021-02-10T19:33:00.416500Z

West 2021-02-10T20:26:49.417200Z

Is there a way to do clustering? I was looking at K-means clustering and other clustering algorithms but I don't know how to create a cluster graph from edges and distances.

2021-02-10T21:37:49.424800Z

If you make up a spring force input file that Might give best possible output, e.g. nodes 1 through 4 are all Yes pairwise with each other, and nodes 5 thru 7 are all pairwise yes with each other, but any of first 4 nodes are no with the last 3, you could see whether neat or other Graphviz programs can โ€œseparateโ€ those groups for you visually. If they cannot do it for a simple input like that, it might not be a useful approach.

2021-02-10T21:38:45.426600Z

In general, if the inputs arenโ€™t so clearly divisible into groups, then the output node placement is going to be less clearcut than the straightforward inputs

aaron-santos 2021-02-16T18:21:54.249Z

> how to create a cluster graph from edges and distances Certainly not a silver bullet, but multi-dimensional scaling can transform pair-wise distances into points in a cartesian space which are then appropriate for clustering.

West 2021-02-08T21:40:29.223900Z

So my dataset has each individual, represented by an alias (the animal names). Each individual responded how many groups they want to be in, and whether they want to be in a group with that individual. I figured a weighted graph would be my best bet.

West 2021-02-08T22:28:04.224100Z

Iโ€™m wondering how I can get a better visualโ€ฆ

2021-02-08T23:00:15.224300Z

As in, if you have 100 individuals, do each of those 100 respond with 99 yes/no "I individual X want to be in a group with individual Y", for all 100x99 (X,Y) pairs?

2021-02-08T23:03:16.224500Z

i.e. is part of the input data you are starting with effectively this NxN table of true/false values? and you must honor those true/false values when creating groups? Or is it more numeric 0 to 10 scale of 10=definitely OK, 0=never, and 5=lukewarm about being in same group with the other individual, and you are trying to create groups not with hard yes/no constraints, but trying to minimize the number of pairs that hate each other in the same group?