beginners

Getting started with Clojure/ClojureScript? Welcome! Also try: https://ask.clojure.org. Check out resources at https://gist.github.com/yogthos/be323be0361c589570a6da4ccc85f58f.
sova-soars-the-sora 2021-02-09T01:12:52.224700Z

@andy.fingerhut the source code looks https://gitlab.com/wildwestrom/group-creator/-/blob/master/src/wildwestrom/grouper.clj like yes/maybe/no/me

2021-02-09T01:18:45.225Z

So is "no" a hard constraint that the two indviduals cannot be put into the same group, or that it is a worse solution, by some measurement of worse? And what does 'me' mean?

2021-02-09T01:22:33.225200Z

In terms of getting some kind of useful visualization for a large number of individuals, there are inputs for which it will probably always look messy. There are graph drawing algorithms that take weights on the edges, and try to make nodes connected by edges with large weights close together (at least 'more often') and nodes connected by edges with small weights farther apart, but there is no way on a 2-dimensional flat surface to place nodes so that the distance between them is equal to the weight of the edge between them, for arbitrary input edge weights.

sova-soars-the-sora 2021-02-09T01:22:59.225400Z

i would think "me" means self... the edge that points back to the node (?) and "no" probably means avoid 100%

sova-soars-the-sora 2021-02-09T01:23:16.225600Z

yeah distance probably doesn't matter... a solid line and dashed line could represent Yes vs Maybe

sova-soars-the-sora 2021-02-09T01:23:49.225800Z

hash tag ideas

2021-02-09T01:24:11.226Z

Possibly relevant Wikipedia article https://en.wikipedia.org/wiki/Force-directed_graph_drawing

2021-02-09T01:25:28.226300Z

The "See also" section of that article mentions that the Graphviz library has some code that can do some variant of this. I haven't used that part of Graphviz before.

2021-02-09T01:26:56.226500Z

I've almost always used the dot command when using Graphviz, but looks like neato, fdp, and sfdp might be useful to experiment with here.

sova-soars-the-sora 2021-02-09T01:30:12.226700Z

Cool! I look forward to seeing if that solves OP's problem.

West 2021-02-09T01:46:31.227Z

I’ll get back to this tomorrow, but thank you for all the responses!

Yang Xu 2021-02-09T02:49:56.229Z

Hi, How to get the key of Enum instead of the value when converting Java object to Clojure map using bean or javadata/from-java?

2021-02-09T03:17:44.230100Z

I don't think I understand your question. If I call bean on a Java object, it returns a value that acts like a Clojure map, and its keys are all keywords, e.g.:

user=> (def m1 (bean (atom 5)))
#'user/m1
user=> m1
{:class clojure.lang.Atom, :validator nil, :watches {}}
user=> (keys m1)
(:class :validator :watches)
user=> (map class (keys m1))
(clojure.lang.Keyword clojure.lang.Keyword clojure.lang.Keyword)

2021-02-09T03:18:22.230800Z

All of the keys are Clojure keywords. You want a map where the keys are some other non-keyword values?

Yang Xu 2021-02-09T03:34:29.235300Z

Sorry, I don't describe it clearly. The problem is I have an Enum in Java like this:

public enum Test {
    A("a", ""),
    B("b", "")
}
So, I want to get the key of Enum when converting Java objects to Clojure maps. Now is get the name of Enum.

2021-02-09T03:56:42.236200Z

Can you give an example of something you have tried in a REPL with such an enum, showing the return value that you get (but wish it were different), and what return value you wish to get? I still do not understand what you are after.

Yang Xu 2021-02-09T04:56:18.243800Z

public class Test {
    private QueryTypeEnum type;

    public enum QueryTypeEnum {
          A("a", ""),
          B("b", "");
          private String key;
          private String desc;
    }
}

(bean test instance) or (from-java test instance) 
My except map is like this: {":type" "a"}, But it will take the name of Enum, so the result will be like this: {":type" "A"}.
Now, I found a way to solve it. IΒ  rewrite defmethod from-java [Enum]Β  inside the java.data like this:
(defmethod j/from-java Enum [enum] (.getKey enum))

popeye 2021-02-09T05:10:42.244300Z

Team , I have a vector like below

[A1 B1 C1  
  A2 B2 C2 
 A3 B3 C3]

popeye 2021-02-09T05:11:06.244800Z

I wanted to split and put it like

[[A1 B1 C1 ][A2 B2 C2 ][A3 B3 C3]]

popeye 2021-02-09T05:11:36.245500Z

so that I can iterate over 3 elements each and pass as argument

popeye 2021-02-09T05:11:43.245700Z

how can I achieve in clojure

aratare 2021-02-09T05:13:04.246100Z

@popeyepwr perhaps https://clojuredocs.org/clojure.core/partition?

emilaasa 2021-02-09T06:12:58.246200Z

(mapv vec (partition 3 [:A1 :B1 :C1 :A2 :B2 :C2 :A3 :B3 :C3]))

emilaasa 2021-02-09T06:13:37.246400Z

PS I'm not very experienced in clj either so take it with a grain of salt πŸ™‚

popeye 2021-02-09T06:32:40.246900Z

@rextruong what if input is like this

["A1 B1 C1"
  "A2 B2 C2" 
 "A3 B3 C3"]

popeye 2021-02-09T06:33:35.247200Z

output should be

[["A1" "B1" "C1" ]["A2" "B2" "C2" ]["A3" "B3" "C3"]]

seancorfield 2021-02-09T06:40:12.248400Z

@popeyepwr (map #(clojure.string/split % #" ") input) will be close to what you want...

seancorfield 2021-02-09T06:41:05.248800Z

user=> (def input ["A1 B1 C1"
                   "A2 B2 C2" 
                   "A3 B3 C3"])
#'user/input
user=> (map #(clojure.string/split % #" ") input)
(["A1" "B1" "C1"] ["A2" "B2" "C2"] ["A3" "B3" "C3"])
user=> 

πŸ‘ 2
βœ… 1
seancorfield 2021-02-09T06:42:01.249500Z

mapv if you really want a vector back instead of a (lazy) sequence.

aratare 2021-02-09T06:44:35.250600Z

Ah sorry I thought they are all separate strings.

emilaasa 2021-02-09T06:56:59.251500Z

Do you want to turn a vector of strings into a vector of vectors of strings? (mapv vector ["A1 B1 C1" "A2 B2 C2" "A3 B3 C3"]) ; [["A1 B1 C1"] ["A2 B2 C2"] ["A3 B3 C3"]]

emilaasa 2021-02-09T06:57:11.251800Z

or am I misunderstanding something πŸ™‚

dpsutton 2021-02-09T07:02:10.253500Z

your solution yields a vector who's elements are single item vectors. ["A1 B1 C1"]. The desired shape is a vector of 3 item vectors [["A1" "B1" C1"] ...]

emilaasa 2021-02-09T07:02:30.253700Z

ah!

dpsutton 2021-02-09T07:03:01.253900Z

yeah it's hard to see on the slack client

emilaasa 2021-02-09T07:03:13.254100Z

Not seeing quotes, probably the biggest time sink in my life πŸ˜„

dpsutton 2021-02-09T07:03:15.254300Z

i had to do a bit of a double take myself

emilaasa 2021-02-09T07:05:29.254500Z

Interesting how the brain works, I looked at the question from one hour ago and then I did not even see the quotes in the revised question

2021-02-09T07:26:05.254800Z

ahhh... i forgot that clojure.string/split functions! gonna take note again.

mbjarland 2021-02-09T09:03:51.256500Z

I assume that if I create a channel with a distinct transducer, eg

(async/chan 10 (distinct))
that this will not be thread safe, i.e. it is not safe for multiple threads to read/write from the channel?

mbjarland 2021-02-09T09:05:08.256900Z

or even just the distinct transducer without the channel

mbjarland 2021-02-09T09:06:33.257500Z

if I wanted a thread safe distinct…what would you choose? locking ?

2021-02-09T09:07:06.257700Z

It is safe

2021-02-09T09:07:47.258900Z

It is a bad idea because distinct will hold a copy of every message that passes through the channel in a set

mbjarland 2021-02-09T09:09:27.260500Z

@hiredman thank you. This is a short lived tree traversal, multi threaded yes, but accumulation is not an issue. Hmm…I read about the volatile used in distinct and came out thinking it would not be safe. Care to elaborate a bit?

2021-02-09T09:11:42.263500Z

The main thing is every channel has a lock inside it, and when you add or remove things from the channel (which is when the transducer operates) you hold the lock

mbjarland 2021-02-09T09:12:13.264300Z

ok got it, so distinct by itself outside a channel is not thread safe, but used as a transducer for a channel we get safety

2021-02-09T09:12:55.265400Z

The usage of volatile inside a lot of the mutable transducers is there to make them safe for use with core.async

2021-02-09T09:13:55.266600Z

The volatile makes sure mutations propagate between threads, the channel lock says one thread at a time

mbjarland 2021-02-09T09:15:01.267500Z

makes sense. Thanks again!

Helins 2021-02-09T09:36:15.270200Z

Damn, I realized I didn't know how to pass a java property using -J (Clojure CLI). I tried many ways of prefixing it without any luck, an example in the reference guide would be welcome

2021-02-09T09:50:40.271200Z

-J-Xmx512m

2021-02-09T09:52:07.272400Z

A property would -J-Dfoo=bar

Helins 2021-02-09T10:02:00.275500Z

All right, it was about the order of args... -J must figure before -M. Kinda makes sense but my coffee wasn't strong enough this morning...

Yang Xu 2021-02-09T12:43:03.280800Z

Hi, I using Java class to representing Clojure dataset like this:

{
  "query": {
    "source-table": 2,
    "aggregation": [
      [
        "distinct",
        [
          "field-id",
          5
        ]
      ],
      [
        "sum",
        [
          "field-id",
          8
        ]
      ]
  }
}
Now, I have classes here:
public class QueryReq {
    private Query query;

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public class Query {
        private String sourceTable;
        private List<Aggregation> aggregation;
    }


    @Data
    public class Aggregation {
        private AggregationEnum aggregation;
        private AggregationColumn aggregationColumn;

        @Data
        public class AggregationColumn {
            private KeywordEnum column;
            private Integer id;
        }
    }
So, my question is how to convert AggregationColumn which nested in the Aggregation to Clojure vector? Is here have some convenient ways to do converting datastructure between Java and Clojure?

Eamonn Sullivan 2021-02-09T13:39:09.286100Z

I'm having some trouble with a reflection warning. I have a library, with a defrecord in it that extends a defprotocol. E.g.. (defrecord SomeThing [name type] myProtocol ...). This protocol has a release-props method. When I make a call to this method, like so:

(.release-props my-thing)
I'm getting a reflection warning call to method release_props can't be resolved (target class is unknown) . I'm trying to resolve it like (.release-props ^mylib/SomeThing my-thing), but that's not working. I get Unable to resolve classname. What am I doing wrong?

Eamonn Sullivan 2021-02-09T14:03:25.286200Z

Maybe I'm missing something on the library side? I admit to having no clue about what (:gen-class) does...

Eamonn Sullivan 2021-02-09T14:04:51.286400Z

even a fully qualified name like ^my.lib.SomeThing doesn't work. I still get a ClassNotFoundException.

Eamonn Sullivan 2021-02-09T14:16:04.286600Z

I guess the most basic question is: how do I refer to a record in a library? I just get No such var

alexmiller 2021-02-09T14:17:03.287500Z

Java method names can’t have a - in them

Eamonn Sullivan 2021-02-09T14:17:50.288900Z

Doh! Showing my Java ignorance again.

alexmiller 2021-02-09T14:17:57.289300Z

So the . call with the - doesn’t seem right

Yang Xu 2021-02-09T14:18:06.289600Z

Anyone know that does java-data/from-java can work with the Java Inner class?

Eamonn Sullivan 2021-02-09T14:18:14.289700Z

It works, though. Just gets a reflection warning.

alexmiller 2021-02-09T14:18:41.290500Z

Yeah, it might be getting munged

Eamonn Sullivan 2021-02-09T14:19:10.290800Z

Ah, right. I'll give these methods more JavaLikeNames, then. Thank you!

alexmiller 2021-02-09T14:19:29.291200Z

The names are fine now

alexmiller 2021-02-09T14:19:46.291900Z

It’s just that calling via java interop requires java naming

Eamonn Sullivan 2021-02-09T14:20:19.292700Z

Excuse the extreme ignorance, but is there another way to call a protocol method here?

alexmiller 2021-02-09T14:20:27.293100Z

If you have a protocol, why are you not invoking the protocol method?

alexmiller 2021-02-09T14:21:07.293800Z

(release-prop my-thing)

Eamonn Sullivan 2021-02-09T14:21:39.294300Z

Because this is the very first time I have used protocols and thought that was how they work.

alexmiller 2021-02-09T14:22:03.295400Z

Ok, they’re just like regular functions when you invoke them

alexmiller 2021-02-09T14:22:39.296900Z

And protocol functions exist in the namespace where they’re declared so you require/refer them just like any other function

Eamonn Sullivan 2021-02-09T14:23:07.297200Z

Bingo, that did it. Thank you!

2021-02-09T14:32:27.300500Z

Hi everybody! From this map:

(def homes [{:name "Home 1",
             :wifi "y",
             :shower "y",
             :laundry "y",
             :metro "n",
             :balcony "y",
             :fireplace "n",
             :pool "y"},
            {:name "Home 2",
             :wifi "n",
             :shower "y",
             :laundry "y",
             :metro "n",
             :balcony "n",
             :fireplace "n",
             :pool "n"}
            {:name "Home 3",
             :wifi "y",
             :shower "y",
             :laundry "y",
             :metro "n",
             :balcony "y",
             :fireplace "y",
             :pool "n"}
            {:name "Home 4",
             :wifi "y",
             :shower "y",
             :laundry "n",
             :metro "n",
             :balcony "n",
             :fireplace "n",
             :pool "n"}]);
I want to only keep/filter houses meeting the following needs (def needs [:wifi :shower :laundry]) Is my solution a decent one? (filter #(every? #{"y"} (vals (select-keys % needs))) homes) Did you have suggestions?
(filter #(every? #{"y"} (vals (select-keys % needs))) homes)

({:name "Home 1",
  :wifi "y",
  :shower "y",
  :laundry "y",
  :metro "n",
  :balcony "y",
  :fireplace "n",
  :pool "y"}
 {:name "Home 3",
  :wifi "y",
  :shower "y",
  :laundry "y",
  :metro "n",
  :balcony "y",
  :fireplace "y",
  :pool "n"})

johnjelinek 2021-02-09T15:06:43.301800Z

is there any possibility to do java interop from source files instead of compiling first? Or is there a way to use deps to build local java libs first before starting the repl?

alexmiller 2021-02-09T15:08:11.302200Z

no to the first question. the latter is possible but probably depends on lots of things

2021-02-09T15:09:01.302400Z

i might consider modeling like this:

(def homes' [{:name "Home 1",
                :amenities #{:wifi :shower :laundry :pool}},
               {:name "Home 2",
                :amenities #{:shower :laundry}}
               {:name "Home 3",
                :amenities #{:wifi :shower :laundry :balcony :fireplace}}
               {:name "Home 4",
                :amenities #{:wifi :shower}}])

2021-02-09T15:09:09.302600Z

(def needs' #{:wifi :shower :laundry})

2021-02-09T15:09:31.302800Z

then to filter:

(filter
   (fn [home] (clojure.set/subset? needs' (:amenities home) ))
   homes')
;; => ({:name "Home 1", :amenities #{:pool :shower :laundry :wifi}}
;;     {:name "Home 3", :amenities #{:shower :laundry :balcony :wifi :fireplace}})

πŸ‘ 2
2021-02-09T15:26:21.303100Z

Thx for your suggestion. Concerning the modeling, let's assume that it can be changed because it comes from a converted JSON.

πŸ‘ 1
2021-02-09T15:32:41.303500Z

I have not tried it before, but do not know of any reason why it shouldn't work, either. Inner classes named from Clojure have names like OuterClass$InnerClass -- did you try naming the inner class that way?

2021-02-09T15:32:55.303700Z

If so, what did you try, and what unexpected result did you get?

uosl 2021-02-09T15:42:06.303900Z

I think your solution is good, although you could simplify it by changing (vals (select-keys % needs)) to (map % needs).

πŸ‘Œ 1
Joel Whittier 2021-02-09T15:55:04.309200Z

Hey, I’m coming from Haskell and excited about clojure! I’m working through 4clojure and some basic problems right now just getting the hang of it. Are there any recommended intro projects out there? Would like to dig into something but I’m not sure what’s reasonable in this language.

Eric Le Goff 2021-02-09T15:55:24.309300Z

While I can solve easy 4clojure puzzles, I am curious about the best learning strategy when stuck. Obviously I can use a search engine for some public gist where other users would share their solution and revert engineer it, but is there a more obvious path to learn ?

popeye 2021-02-09T16:15:02.309700Z

Team I am getting

Caused by: java.lang.Exception: Cyclic load dependency:

popeye 2021-02-09T16:15:19.310200Z

i understand that using namespace one in another

popeye 2021-02-09T16:16:09.311300Z

is there anyway to avoid it? I wanted to use one of the function from another namespaces, which already I imported the file in another

2021-02-09T16:18:44.311500Z

Perfect @regen! I suspected that there was a way to simplify. Thank you, that was exactly the advice sought. πŸ‘

2021-02-09T16:20:30.312100Z

Maps as functions ... it's really powerful!

pavlosmelissinos 2021-02-09T16:27:16.318Z

@popeyepwr Imho, this is usually a sign that you need a namespace restructuring. In other words, think again whether you really need a relationship like ns a -> ns b -> ns c -> ns a (read -> as requires). Usually the part of a that requires b is higher level than the part that c is using. So, assuming that all of the affected namespaces are under your control, it might make sense, depending on the case, to either: β€’ further break them down (to split the higher from the lower level stuff of a) or β€’ merge the interconnected parts into a single namespace

πŸ‘ 1
2021-02-09T16:27:18.318100Z

extract out the shared code into a new namespace

clyfe 2021-02-09T16:35:07.319600Z

There's also a technique by which stuff is moved at runtime ((resolve 'my.nsp/f) arg1 arg2) generally not good practice.

πŸ‘ 1
clyfe 2021-02-09T16:38:05.320600Z

Of interest, there is also Timothy Baldridge's answer here (use interfaces and implementations): https://groups.google.com/g/clojure/c/-PvQvVmmLQg

πŸ’― 1
uosl 2021-02-09T16:47:15.320900Z

Yes, and it doesn't just stop at maps [=

2021-02-09T16:49:55.321100Z

Yes, sets as function too πŸ™‚

2021-02-09T16:51:08.321300Z

Java classes pretty much all have custom APIs defined by their methods, so I cannot imagine any general technique to convert between Java object values and Clojure values. If you use Java classes that implement interfaces like List, Map, and Set, Clojure collections implement those interfaces, so at least in some cases no conversion is necesary -- they already satisfy those interfaces.

johnjelinek 2021-02-09T17:40:25.322Z

are there any reference apps or starter kits that include this workflow for reference?

alexmiller 2021-02-09T17:43:38.322200Z

are these local java libs things that are yours or external libs? the latter is nearly always built and published to a maven repo somewhere and you should just include the lib that way.

alexmiller 2021-02-09T17:44:46.322400Z

are you looking at java-only or java/clojure mix?

johnjelinek 2021-02-09T17:53:24.323700Z

so, my use-case is running the terraform CDK (`cdktf`). It ships with a java flavor (but also typescript, python, and dotnet-core as well), and when you add provider dependencies (ie: docker), you run cdktf get and it pulls down some typescript and generates java source to be consumed by your project. For a java project, it then is accessible by the code you've written yourself, but for clojure -- it's not yet compiled. Usually cdktf get code is not checked into the repo, it goes in a .gen directory.

johnjelinek 2021-02-09T17:55:56.324Z

but my use-case is to only write clojure with java interop

phronmophobic 2021-02-09T18:05:40.324800Z

if you don't need to recompile very often, I was able to use this one liner to compile java files:

find javasrc -name '*.java' -print0 | xargs -0 javac -d classes -cp `clj -Spath
` make sure the directory classes exists and add it to the paths in your deps.edn which should have a key like:
:paths ["src" "resources" "classes"]

mathpunk 2021-02-09T18:07:13.326100Z

I'm trying to do a reduction (or something else.... catamorphic? lots into 1) but I'm having trouble figuring out exactly how to shape it. The first def is an example from the docs of a library I'm trying out, and the second is the way that my data is shaped.

(def g1 (-> (dep/graph)
            (dep/depend :b :a)   ; "B depends on A"
            (dep/depend :c :b)   ; "C depends on B"
            (dep/depend :c :a)   ; "C depends on A"
            (dep/depend :d :c))) ; "D depends on C"

(def my-data {:a #{:b :c}
              :b #{:d :c}
              :d #{}})

mathpunk 2021-02-09T18:07:32.326200Z

The end goal is a dependency graph of all that data

mathpunk 2021-02-09T18:08:25.326400Z

There's a sort of double higher order fn going on: for every key, I want to put all its dependents into this growing dependency graph

mathpunk 2021-02-09T18:08:51.326600Z

maybe I should be using a loop-recur form

2021-02-09T18:10:52.326800Z

You have basically two options 1. Reduce over the map, reducing over each map entry 2. Transform your map into a more linear structure, then reduce over that

mathpunk 2021-02-09T18:12:17.327Z

i'm getting thrown by f should be a function of 2 arguments in reduce's docs. This is a 3 argument function. At first I thought, use partial, but the first argument of dep/depend is that graph that's accumulating

2021-02-09T18:12:42.327400Z

it is two arguements

2021-02-09T18:12:53.327600Z

the graph and a map entry (which is a pair)

mathpunk 2021-02-09T18:13:06.327800Z

oh ho

2021-02-09T18:13:40.328Z

the above is an example of choice 2

mathpunk 2021-02-09T18:17:26.328200Z

so the linearized version of what i started with would be something more like

[{:depends :a, :depends-on :b}
 {:depends :a, :depends-on :c}
 {:depends :b, :depends-on :d}
 {:depends :b, :depends-on :c}
 {:depends :d}]
?

2021-02-09T18:17:42.328400Z

sure

2021-02-09T18:18:09.328600Z

or even just a bunch of pairs like [:a :b], the relationship implied by the context

1
2021-02-09T18:20:08.328900Z

when "linearizing"(normalizing? it is connected in some way to normalizing data for a rdms) your structure like that you have two choices in how to do it, via seqs or via transducers

2021-02-09T18:22:10.329100Z

using a for like in my example produces a lazy seq, lazy seqs are sort of a habitual thing to grab for, but transducers are often faster, use less memory, and behave nicer when mixed with io/side effects

mathpunk 2021-02-09T18:22:45.329300Z

when i finally run this function, i anticipate running it approximately once. so i'll skip the transduction

mathpunk 2021-02-09T18:23:10.329500Z

so where you have that empty map in your db def, i would have (dep/graph), which is the empty val for my case

mathpunk 2021-02-09T18:24:26.329700Z

cool, it was not hard to linearize this, and that does make it easier to think about

mathpunk 2021-02-09T18:28:43.329900Z

(defn linearize [[component references ]]
  (for [ref references]
    [component ref]))


(def normalized (mapcat linearize adjacency-list))


(def dependency-graph
  (reduce (fn [g entry] (dep/depend g (first entry) (second entry))) (dep/graph) normalized))
Piece of 🍰 , thanks hm!

popeye 2021-02-09T19:26:18.330300Z

Team I have below var

(def var [{:a "a1":b "b1" :c "c1"}
 {:a "a2" :b "b2" :c "c2"}])

popeye 2021-02-09T19:26:37.330800Z

want to collect the values like below

popeye 2021-02-09T19:26:44.331Z

[[a1 b1 c1] [a2 b2 c2]]

johnjelinek 2021-02-09T19:27:16.331400Z

OH! That's interesting

popeye 2021-02-09T19:27:18.331600Z

cannot use vals

popeye 2021-02-09T19:27:49.331900Z

wanted to fetch according to keys

popeye 2021-02-09T19:28:03.332300Z

I tried something like

(mapv #(get var %) [:a :b :c])

popeye 2021-02-09T19:28:15.332500Z

but did not help

popeye 2021-02-09T19:30:48.334200Z

thing is

:a :b :c

popeye 2021-02-09T19:30:56.334600Z

will not be in order in each map

2021-02-09T19:31:20.335500Z

var is 1. a really bad name to use because it conflicts with the var special form 2. a vector of maps

popeye 2021-02-09T19:31:22.335600Z

so need to pull it from each map,

2021-02-09T19:32:47.336300Z

so for example (get [{:a 1}] :a) is not going to return anything useful

2021-02-09T19:33:15.336600Z

which is what your map is doing

2021-02-09T19:33:19.336800Z

mapv

popeye 2021-02-09T19:35:35.338600Z

(def var {:a "a1":b "b1" :c "c1"})
=> #'user/var
(mapv #(get var %) [:a :b :c])
=> ["a1" "b1" "c1"]

jonathan 2021-02-09T19:36:13.339200Z

hi, I'm struggling with hyphens in clojure.java.jdbc. I'm using SQLITE and have a column user_id. I'm doing a simple insert like this:

(jdbc/insert! db :user {:user-id 555} {:identifiers #(.replace % \- \_)})
Getting the error: SQL error or missing database (near "-": syntax error)

jonathan 2021-02-09T19:36:35.340100Z

tried using that :identifiers key to fix the hyphens but it seems too have no effect

popeye 2021-02-09T19:36:43.340300Z

if vector as multiple map values thn it shouls extract

2021-02-09T19:37:15.340500Z

nope

2021-02-09T19:37:57.341400Z

get looks some thing up by a key in the immediate thing you give it, it will not reach down through other collections to look for something with a key

seancorfield 2021-02-09T19:38:08.341500Z

:identifiers deals with names coming back from SQL to Clojure; :entities is what you want for names going from Clojure to SQL.

jonathan 2021-02-09T19:39:04.341700Z

thanks sean wow really nice to get a reply from the author so fast!

jonathan 2021-02-09T19:39:44.341900Z

would love to use next.jdbc but due to circumstances out of my control I need to target JDK7

seancorfield 2021-02-09T19:39:45.342100Z

I try to keep an eye out for SQL-related Qs here in #beginners -- posting in #sql is certain to get my attention more quickly tho'... πŸ™‚

jonathan 2021-02-09T19:39:52.342300Z

πŸ™‚

jonathan 2021-02-09T19:41:10.342500Z

that worked thanks

lispyclouds 2021-02-09T19:44:52.342700Z

So the issue is that for each of the keys [:a :b :c] you need to call (get) on each of your maps. so its a nested iteration

lispyclouds 2021-02-09T19:45:52.342900Z

you need to do it the inner fn that youre passing to mapv for each of your keys

lispyclouds 2021-02-09T19:47:56.343100Z

see if using https://clojuredocs.org/clojure.core/for in the mapping function helps?

popeye 2021-02-09T20:00:27.343600Z

@hiredman I wrote this

(map  (fn [x] (mapv #(get x %) [:a :b :c])) var)

2021-02-09T20:04:53.345900Z

Looks nice, you might want to use mapcat, and again, don't use the name "var" it conflicts with the var special form, and will act really odd in some situations

popeye 2021-02-09T20:15:39.346200Z

yeah sure, i have something else in my code

zackteo 2021-02-09T22:34:58.355600Z

Hello, am currently trying to prototype a simple clojure backend with Ring. Am using https://github.com/lispcast/listronica/tree/1.17 as a template. Are there any resources I might want to look at? How do I best create an API to transmit edn from a clojurescript webapp to ring backend? Can I just put edn in the :body of a route? That gives me some errors. Do I wrap it in a string like "{:test [\"test\"]}"

ej 2021-02-09T22:39:49.358900Z

I'm reading Web development with Clojure (3rd ed.) and I noticed that the book starts off with what I would consider traditional web development, then introduces AJAX with ClojureScript, before adding reagent and eventually re-frame. I love the book, but this seems like a lot of additional complexity to me, and I'm wondering if I need that additional complexity. I want to make simple and fast websites with text fields for inputting some data, and some buttons and checkboxes for filtering said data. If I need fancy animations I can use CSS. I don't think I need reactivity, but maybe I would be missing something else? Is the workflow of using reagent (with reframe?) somehow more productive than just writing Clojure on the server and producing HTML? Asked in another way, what are some good use cases for ClojureScript with reagent?

seancorfield 2021-02-09T22:51:15.361200Z

"Modern" web apps these days are SPAs (single page applications) that communicate with a REST-like backend -- and that's what the book is aiming at. It's why I don't recommend that book -- or the Luminus template -- for people who are brand new to Clojure: it's just too many moving parts. Take a look at the Practicalli stuff for web development and start simple with just Ring and a few small, simple libraries. Then as you understand that process, you can add complexity as you need it.

seancorfield 2021-02-09T22:52:48.361600Z

https://practicalli.github.io/blog/posts/clojure-web-server-cli-tools-deps-edn/ (at https://practicalli.github.io/ -- lots of great beginners content there).

ej 2021-02-09T23:06:09.368100Z

I will take a look, @seancorfield. Thanks for the suggestion! I think my question could be asked as "How do you decide if an SPA is the right fit?", if anyone has input on that instead πŸ™‚

seancorfield 2021-02-09T23:14:27.370200Z

I think you've answered your own question there @endrejoh -- if you want to make simple/fast websites with forms for capturing data and storing it somewhere, then SSR (server-side rendered) HTML is going to be just fine and Ring + Compojure + maybe Selmer + next.jdbc is about all you'll need (assuming a database for storage). Take a look at https://github.com/seancorfield/usermanager-example (or the Reitit-based variant linked in the README).

ej 2021-02-09T23:20:08.370800Z

Thank you so much, @seancorfield!

evocatus 2021-02-09T23:46:04.371500Z

I have a function that takes 3 arguments. How do I call it if I have arguments packed in a list?

Darin Douglass 2021-02-09T23:46:53.371800Z

(apply my-fn args)

πŸ‘ 2