Fork me on GitHub
Aleks Abla03:11:12

hey everyone, working on a querying problem. It's a fun one. I have a database from which I have to make a csv slurp. the columns would be: (1) name, (2) group, (3 &amp; ...) interests interests is a nested map {:interests {:sports {:football :tennis} :brands {:gucci :java} } }. I would like to slurp out a doc, and for the respective name, I mark in columns (3 & ...) whenever the value of a particular interest is true.

Aleks Abla03:11:10

an example slurp

Aleks Abla03:11:43

an idea would be to to string and interpose (str name ", " group ", " some kind of loop here marking true for the interests)


What database, and what format are the columns?

Aleks Abla03:11:48

double checking now, i think it's firebase.

Aleks Abla03:11:58

thanks for the help, i really appreciate it.


(and you say "make a csv slurp" but do you mean produce a CSV file from the database?)

Aleks Abla03:11:37

yes, I am trying to produce it from the database, via slurping into a .csv


@ablazevix Is :interest's value always exactly two levels deep? And you want to "throw away" the middle level (`:sports`, :brands)?

Aleks Abla03:11:58

No, it varies largely. Preferably would like to, yes.


@ablazevix How you turn that structure into flat columns with true/false is going to depend pretty critically on the structure of that data...

Aleks Abla03:11:17

@U04V70XH6 Would you mind explaining the different structures there are.. sorry I am an intern with little CS background.


I just mean that if your interests value has a whole bunch of different shapes, you need to know what those shapes can be in order to turn that into a flat set of true/false columns.


@ablazevix for a two-level map like that:

user=> (def interests {:sports [:football :tennis] :brands [:gucci :java]})
user=> (zipmap (mapcat val interests) (repeat true))
{:football true, :tennis true, :gucci true, :java true}
That will only work for two levels where you are throwing away the top level.

Aleks Abla03:11:46

that actually would work perfectly. the depth is double, but there might be more values under the specific interests i.e. there might 7 sports, but only 5 brands.


Size won't matter in this case.


(mapcat val interests) throws away the top level keys and con`cat`enates all the values from those keys.

Aleks Abla03:11:37

wow... don't you just love clojure.. I am so thankful for finding it so early on.. it's taught me a lot of good basics


I've been programming professionally for 35+ years and I've been doing Clojure for the last 8, nearly 9, of them -- and I'm the happiest I've ever been writing software!

Aleks Abla03:11:28

yea, i don't blame you.. rich hickeys charm can do that to ya

Aleks Abla03:11:03

maybe a slightly harder version of the previous problem -- what if we wanted to slurp it out this way

Aleks Abla03:11:18

we would have (1 group, 2 & .. Interests, with mappings of people in interests. sound computationally expensive haha!)


@ablazevix That would just be (zipmap (mapcat val interests) (repeat (:name row)))


The main issue you'll have here is that for the CSV file you'll need the union of all the interests across all rows so you know which columns to use as headers, and then you'd need to inflate each row to have blanks/`nil` for the "missing" columns for a given row..


Hi, I'm trying to use luminus +boot +hoplon and can't understand how to get it to work correctly with cider. Does anyone has an experience with it?


@ozanzal can you start a repl?


Well, running boot figwheel repl results in this error, however, a repl does seem to start and I can connect to it with Cider, but when I connect to it It seems broken, no autocompletion, and a lot of ClassNotFound exceptions when I try to evaluate functions


for example:


The first error is "Address already in use". The second error looks like you did (in-ns foo) before foo was loaded or required


the symptom being that it appears clojure.core is not loaded and it doesn't know what + is


Oops, looks like that was part of the problem, I needed to "(require 'user)"


Thank you!


you should be in user by default. what happens if you do neither require or in-ns?


Looks like what I was trying to do was needed for starting the app from within the repl, But I feel I need to do some homework, I wasn't requiring things properly, now I get it to work better, But I still need to understand figwheel better


I'd take care of the "address already in use", I guess you are somehow running two instances of a server


Also, the clojure repl is "mutable", meaning you can only call functions that have been defined (evaluated), and you can only reference namespaces that have been loaded


I normally eval the whole namespace (if it's compilable) and then evaluate each function that I want to (re)write so the repl gets the updated version


Thanks @mping,I'm trying to evaluate the projects core, and it looks like there is a problem locating env

Alyssa Herzog21:11:30

Not sure if this is the correct place, so sorry if not! Does anyone have any resources to help advocate for clojure in their place of employment? A few teams are still on Java, others C# (mostly business dev and linear broadcast teams), but most are python, node.js, or golang.

Nima G23:11:16

Hackatons are usually a good time to just do something in Clojure and win their hearts 😉

Alyssa Herzog05:11:01

@U2J4FRT2T one day I'd like for WarnerMedia to be listed there


Hello everyone, I have some functions that are kind of tricky to manually fix (they need to preprocess their input in some specific ways). I am working on a macro to aid in making the changes easier to implement. I've got a working prototype of what I want, but there is a tiny bit of syntax that I would like to improve. I've got this:

(defn fix-input
  (println "fixing input")

(defmacro def-fixed
  [symbol attr-map body]
  `(def ~(with-meta symbol attr-map)
     (comp ~body fix-input)))

(def-fixed funky
  {:some-meta true}
  (fn [x] (inc x)))

(funky 5)
(meta #'funky)
But I would like to have the syntax be like this:
(def-fixed funky
  {:some-meta true}
  (inc x))
So that I have a syntax more similar to defn. How could I achieve this?


(defmacro def-fixed
  [symbol attr-map arglist & body]
  `(def ~(with-meta symbol attr-map)
     (comp (fn ~arglist [email protected]) fix-input)))
(cmd)user=> (macroexpand '(def-fixed funky {:some-meta true} [x] (inc x)))
(def funky (clojure.core/comp (clojure.core/fn [x] (inc x)) user/fix-input))

noisesmith23:11:02 I think that's the specific input and expansion you want


exposing the metadata

user=> (binding [*print-meta* true] (pr-str (macroexpand '(def-fixed funky {:some-meta true} [x] (inc x)))))
"(def ^{:some-meta true} funky (clojure.core/comp (clojure.core/fn [x] ^{:line 1, :column 91} (inc x)) user/fix-input))"


the only tricks were using & foo in order to allow arbitrary forms in the emitted function, and explicitly binding then templating an arglist


the & isn't strictly needed, but makes it act like most other functions that allow a body argument


nice, thanks for the tips!