Fork me on GitHub
#clojure
<
2019-11-19
>
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)

seancorfield03:11:14

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.

seancorfield03:11:01

(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

seancorfield03:11:18

@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.

seancorfield03:11:56

@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.

seancorfield03:11:50

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.

seancorfield03:11:57

@ablazevix for a two-level map like that:

user=> (def interests {:sports [:football :tennis] :brands [:gucci :java]})
#'user/interests
user=> (zipmap (mapcat val interests) (repeat true))
{:football true, :tennis true, :gucci true, :java true}
user=>
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.

seancorfield03:11:29

Size won't matter in this case.

seancorfield03:11:04

(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

seancorfield03:11:36

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!)

seancorfield03:11:45

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

seancorfield03:11:41

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..

Oz14:11:21

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?

mping14:11:43

@ozanzal can you start a repl?

Oz14:11:57

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

Oz14:11:39

for example:

dpsutton14:11:25

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

dpsutton14:11:50

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

Oz14:11:40

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

Oz14:11:51

Thank you!

dpsutton14:11:19

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

Oz14:11:28

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

mping14:11:21

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

mping14:11:02

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

mping14:11:35

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

Oz15:11:37

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

diego.videco23:11:53

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
  [input]
  (println "fixing input")
  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}
  [x] 
  (inc x))
So that I have a syntax more similar to defn. How could I achieve this?

noisesmith23:11:19

(defmacro def-fixed
  [symbol attr-map arglist & body]
  `(def ~(with-meta symbol attr-map)
     (comp (fn ~arglist ~@body) fix-input)))
#'user/def-fixed
(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

@diego.vid.eco I think that's the specific input and expansion you want

noisesmith23:11:47

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))"

noisesmith23:11:30

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

noisesmith23:11:19

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

diego.videco23:11:39

nice, thanks for the tips!