clojure

New to Clojure? Try the #beginners channel. Official docs: https://clojure.org/ Searchable message archives: https://clojurians-log.clojureverse.org/
devn 2020-09-11T01:56:08.186400Z

https://gist.github.com/devn/05ad3e7e1266cf1fa781f27b25900c2b Any suggestions on making this cleaner? I put together a multimethod version which dispatches on (:type node) but I know there’s a cleaner way to do this.

dpsutton 2020-09-11T02:01:34.186600Z

i did something very similar to this recently

dpsutton 2020-09-11T02:02:27.186800Z

(defn hoist-maps [[n & rst] m]
  (when n
    (let [n (if (vector? n) (first n) n)
          top-level (medley/map-keys (fn [k] (kwds/kwd n "." k)) m)]
      (if rst
        (let [descend (first rst)
              [child-key option] (if (vector? descend) descend [descend])
              children (get m child-key)]
          (if (or (seq children) (not= option :optional))
            (map (fn [sub] (merge top-level sub))
                 (mapcat (partial hoist-maps rst)
                         children))
            [top-level]))
        [top-level]))))

😫 1
dpsutton 2020-09-11T02:02:39.187Z

(hoist-maps [:incidents :claims :transactions]
              {:name "bob jones"
               :claims [{:category "hurt"
                         :thing "foot"
                         :transactions [{:amount 1}
                                        {:amount 2}
                                        {:amount -3}]}
                        {:category "emotional"`
                         :thing "tired"}]})

dpsutton 2020-09-11T02:03:30.187200Z

ah, i missed that yours could have more "top level" versions

2020-09-11T03:41:54.188500Z

It is just a recursive for

2020-09-11T04:02:46.190600Z

Hi, I have been using clojure/core.match in my code, and while building uberjar I am getting File name too long . Does anybody here has been hit by the same issue before and what can be done to fix the issue ?

seancorfield 2020-09-11T04:09:00.190900Z

@aman.shah5673 How are you building the uberjar?

seancorfield 2020-09-11T04:09:10.191200Z

Also, what O/S are you on?

2020-09-11T04:21:13.192100Z

@seancorfield lein uberjar and OS is ubuntu 18.04

seancorfield 2020-09-11T04:22:59.192800Z

Hmm, then I'm a bit surprised about that.

2020-09-11T04:27:31.193700Z

I have heard of that coming up with core.match because of the way some of its macros behave. This issue is related, although doesn't mention core.match: https://clojure.atlassian.net/browse/CLJ-1852

2020-09-11T04:28:46.194300Z

I have seen people complaining about it too for core.match https://ask.clojure.org/index.php/3824/clojure-generated-class-names-length-exceed-file-system-limit

devn 2020-09-11T06:06:06.194700Z

I assume you’re right, but I don’t follow. 😞

2020-09-11T06:28:59.195300Z

((fn f [lst node]
   (let [typed-node (and (map? node)
                         (contains? node :id)
                         (contains? node :type))
         lst' (if typed-node node lst)]
     ((if (and lst typed-node)
        #(cons {:from (:type lst) :from-id (:id lst) :to (:type node) :to-id (:id node)} %)
        identity)
      (for [a (if (map? node) (vals node) node)
            :when (coll? a)
            i (f lst' a)]
        i))))
 nil
 {:id   "A"
  :type "A"
  :foo  [{:type "B"
          :id   "B"}
         {:type "C"
          :id   "C"
          :bars {:these {:data nil}
                 :keys  {:data {:type "D"
                                :id   "D"}}
                 :are   {:data []}
                 :not   {:data {:type "Q"
                                :id   "Q"}}}}
         {:type "E"
          :id   "E"
          :bars {:guaranteed {:data {:type "F"
                                     :id   "F"}}}}
         {:type "G"
          :id   "G"
          :bars {:to-be-uniform {:data {:type "H"
                                        :id   "H"}}}}]})

devn 2020-09-11T06:51:57.195500Z

ahhhh

devn 2020-09-11T06:52:05.195700Z

i was screwing with

(let [m {:id 1
         :type "A"
         :relationships [{:id 2
                          :type "B"}
                         {:id 3
                          :type "C"
                          :anyting {:data {:id 4
                                           :type "D"}}}]}
      id (:id m)
      type (:type m)]
  (for [vs (vals m)
        :when (coll? vs)
        v vs]
    {:from-id id
     :from-type type
     :to-id (:id v)
     :to-type (:type v)}))

devn 2020-09-11T06:52:12.195900Z

but that only got me one layer in

devn 2020-09-11T06:54:39.196100Z

im going to have to stare at this for a bit

2020-09-11T07:45:27.197900Z

I’m almost getting a crisis 😑 vacation ends Sunday and on Monday I have to do C# again at work.

😬 3
vlaaad 2020-09-11T07:56:17.198300Z

sneak in some F#

👍 2
2020-09-11T08:11:13.200700Z

That’s what I’m working on since 1.5 years (Talking about the many benefits of F# - in a . NET environment / infrastructure) and now I have one colleague who’s interested but all other people there - don’t understand the benefits and don’t want it.

2020-09-11T08:14:05.203700Z

I got told C# is what has to be done, period.

vlaaad 2020-09-11T08:34:59.208Z

I have the same problem on my current work (java)

vlaaad 2020-09-11T08:35:10.208400Z

don’t know what I can do about that

vlaaad 2020-09-11T08:35:45.209Z

show it’s better, they say

vlaaad 2020-09-11T08:38:08.209600Z

but it’s not like I have a lot of time to rewrite systems in clj to show how better it is when there are stupid java bugs to fix

👍 1
Helins 2020-09-11T09:23:25.216100Z

Small thing, but I have been using the following simple convention when dealing with plural names. As humans we are tempted to rely on English but it is consistently inconsistent when programming (see debates on naming SQL tables, datum Vs data, and so one). Reminiscent of regexes, why not append '+' to a singular name in order to designate a collection ? entity+ instead of entities ? Easy and consistent. However, it might get tricky when exchanging data across langs.

vlaaad 2020-09-11T09:34:39.217200Z

why not entity*? + implies 1 or more, while s / * usually means 0 or more

vlaaad 2020-09-11T09:35:37.217800Z

anyway, I’m fine with a little bit of ambiguity, I know the language :D

Helins 2020-09-11T09:40:46.218200Z

Indeed, but * already holds different meanings in Clojure

simongray 2020-09-11T10:46:29.224500Z

I think both + and * are bit too overloaded. Personally I prefer pluralising using the English grammar rules and when that is impossible (singular or plural are identical or when using a word from another language) I just append “-items” to the singular word. Readability is more important than character count or regularity IMO. Besides, having one simple rule for words that can’t be pluralised isn’t that irregular anyway ;)

👍 3
Gleb Posobin 2020-09-11T13:48:45.226100Z

What are the possible reasons for using #'x instead of x? Looking at the reagent template that luminus generates and it is using the former. Yet changing it to the latter keeps the code working.

alexmiller 2020-09-11T13:50:15.227200Z

the former is a var and will "see" changes if the var is rebound during the life of the server

Gleb Posobin 2020-09-11T13:50:40.227800Z

Ah, if I do (def x) in repl?

alexmiller 2020-09-11T13:50:44.228Z

so the former lets you modify your code, with the server running, and immediately see those changes

alexmiller 2020-09-11T13:51:25.228800Z

x is var which is a box holding a value. #'x is a reference to the box

Gleb Posobin 2020-09-11T13:51:31.229Z

I see, makes sense! Thank you.

alexmiller 2020-09-11T13:51:44.229200Z

x will be evaluated to the value inside the box

alexmiller 2020-09-11T13:52:55.230300Z

if you invoke #'x and x holds a function, it invokes the function. this is slower but more dynamic.

Gleb Posobin 2020-09-11T13:54:37.231800Z

Yeah, I have been using defn instead of def to do that before, haha, didn't know there is a better way.

alexmiller 2020-09-11T13:57:39.232700Z

no difference either way

alexmiller 2020-09-11T13:58:14.233300Z

defn is essentially just def fn - the difference here is in how you refer to x

Gleb Posobin 2020-09-11T14:03:00.234Z

How do I get the value inside the var if I have #'x?

alexmiller 2020-09-11T14:05:37.234500Z

you can deref it - @#'x

Gleb Posobin 2020-09-11T14:07:07.235300Z

I see, and if x is a function, (#'x) will just do (@#'x) for me?

alexmiller 2020-09-11T14:08:09.235500Z

yep

👍 1
2020-09-11T14:11:31.238Z

That @alexmiller is investing his precious time to explain things that you could learn yourself by reading a book. 👍:skin-tone-2:

dpsutton 2020-09-11T14:18:20.239300Z

@info902 i think that came off a little rude. understanding the subtleties of vars can be quite tricky and its a natural question. the question was completely appropriate for the channel and i'm happy to have followed along on the discussion.

➕ 6
2020-09-11T14:18:52.240Z

Sorry 😐 I’m not a native speaker

2020-09-11T14:19:43.241200Z

Perhaps I’ve chosen the wrong words

dpsutton 2020-09-11T14:19:52.241400Z

no worries. most everything can be learned from a book. but sometimes its hard to know which concept you need to look up.

alexmiller 2020-09-11T14:20:51.242200Z

yeah, I'm capable of deciding how to spend my time, thanks :)

😁 2
Michael W 2020-09-11T14:26:13.246500Z

I thought he meant he thought it was cool that alex would take the time instead of just saying RTFM.

👍 1
2020-09-11T14:26:40.246700Z

Yeah

alexmiller 2020-09-11T14:26:45.247Z

oh, well cool then :)

2020-09-11T14:26:59.247400Z

I have two books of?/by Alex on my desk

2020-09-11T14:32:06.252400Z

Its sad that there are not more Clojure jobs out in the wild, especially in Germany.

2020-09-11T14:33:03.253600Z

Right now I can only learn & practice in my spare time.

alpox 2020-09-11T14:36:55.254700Z

Same in Switzerland 😞

Las 2020-09-11T14:39:54.255200Z

where are you based?

dpsutton 2020-09-11T14:40:17.256300Z

(i apologize for misreading @info902)

2020-09-11T14:40:20.256400Z

As I have a family and cant move I need to start my own side project in Clojure

2020-09-11T14:41:24.257600Z

@dpsutton its okay, I have to work on my English skills

2020-09-11T14:45:23.260200Z

There is a #business channel but zero activity? I wonder why ? Clojure is the perfect programming language for Startups...

2020-09-11T14:47:10.260500Z

Hi

2020-09-11T14:47:21.261Z

Germany Heidelberg/ Mannheim

2020-09-11T14:47:51.261700Z

You are making your face a secret Las 😉

alexmiller 2020-09-11T14:52:45.262100Z

they're too busy :)

👍 3
2020-09-11T14:53:11.262600Z

The only right answer 😝

2020-09-11T15:21:52.262900Z

Heidelberg is a beautiful city!

2020-09-11T15:22:06.263200Z

So jealous. Wish I could be there this time of year especially.

2020-09-11T15:22:07.263400Z

Indeed

Mark Gerard 2020-09-11T15:22:27.263600Z

I agree, been to Sinsheim and I loved how green it was.

2020-09-11T15:23:35.265Z

I'm sure the local authorities are happy about all new StartUp founders who will settle there 😎

2020-09-11T15:25:30.265600Z

Might seriously consider depending on how the next election cycle goes 😬

bill 2020-09-11T15:50:56.266400Z

on https://news.ycombinator.com/item?id=24038520https://news.ycombinator.com/item?id=24038520 I found https://pitch.com/ in Berlin (checks map…learns it’s a 6 hour drive from Heldelberg)

2020-09-11T16:05:37.266700Z

@info902 There are #jobs #jobs-discuss #jobs-remote and a few other jobs related channels here, that might help you find ideas or approaches that have worked for others

👍 1
2020-09-11T16:24:12.271100Z

@bill that’s already at the order edge of my country 😄

emccue 2020-09-11T20:51:12.275Z

(bind [m {:a 3}
       #{a} m] 
  a)

😮 1
emccue 2020-09-11T20:51:17.275200Z

sometimes i feel like i go too far

devn 2020-09-11T22:46:10.275800Z

I… uh…