Fork me on GitHub
#beginners
<
2020-01-25
>
Kamuela01:01:16

Is Lumo probably what I’m looking for if I want to work primarily with Clojure in the Node.js ecosystem?

Kamuela01:01:40

Maybe Planck

noisesmith01:01:28

planck doesn't use node

noisesmith01:01:11

it uses javaScriptCore, which is an os-specific js api, so it's useful for doing system /scripting but you can't use node specific features or libraries

noisesmith01:01:05

with planck you can use the clj deps tool to manage libs, with lumo you'd use node

dpsutton01:01:57

If you want to target nodejs just use shadow-cljs. It will wrap the normal clojurescript compiler and make your life easier

noisesmith01:01:23

that's fair, then you use java but just on the build / compile side

dpsutton02:01:28

Yeah. It’s quite nice and makes using npm deps extremely easy. I prototyped a simple tui with blessed.js which is a port of ncurses and it was effortless

Kamuela02:01:57

It’s not really that I’m trying to escape java at all costs. I don’t mind it for tooling. It’s just that most of my experience is in the JS ecosystem, so it’s what I understand

Kamuela02:01:33

So when I think of interop I think of JS on NPM rather than Java with Maven

dpsutton02:01:24

Clojurescript is a clojure program so that’s most likely in your build chain. I think unfortunately the maintainer of lumo has stepped back. Planck is amazing but I haven’t gotten a good dev setup with it

dpsutton02:01:20

Go with shadow as the default until you need something different. I would guess that’s not gonna be an issue though

Kamuela02:01:43

I’ve tried to play with shadow a bit, but I find it difficult to follow the docs. Lumo has at least been easy (until probably running into a bug or two)

dpsutton02:01:20

Need some help with shadow? I honestly wouldn’t even consider a different cljs build chain these days

❤️ 1
Kamuela02:01:01

Yes I probably do. Let me sleep on it though and take a crack at it tomorrow—I’ll ping you after I know concretely where things get hazy for me, if that’s ok

seancorfield03:01:45

@kamuela There's a #shadow-cljs channel here if you're not already in that...

🙏 1
jakuzure13:01:29

Hi, when I'm working with APIs I'm mostly extracting the stuff I need via a usually rather huge let which doesn't feel quite right to me, does anybody have a better suggestion of doing that? Example: (defn weatherdata [d] (let [main (:main d) deg (:temp main) feel (:feels_like main) city (:name d) sys (:sys d)] (str ...

Matti Uusitalo13:01:00

Look into associative destructuring

nbardiuk13:01:13

(defn weatherdata
  [{{deg :temp feel :feels_like} :main
    city :name
    sys :sys}]
  (str [deg feel city sys]))

Matti Uusitalo13:01:17

Your code is fine though

👍 1
jakuzure13:01:36

that looks cleaner, thanks!

Parker18:01:11

Hi, I'm working with next.jdbc and I'm having a hard time coming to terms with, what looks like, the need to restructure a hash map into two vectors (for columns and row values). My data looks like this:

#{{:key "value"} {:key "value2"}}
But I haven't been able to find a way to next.jdbc.sql/insert-multi! without restructuring to multiple vectors. Am I missing something? Including possibly a reason for this limitation...

seancorfield18:01:54

@parkerjohnsonwebdev Because for insert multi you want a single batch insert operation to happen (as opposed to insert! which does a single row operation).

seancorfield18:01:21

So the SQL is insert ( column names ) values ( first row ), ( second row ), etc

seancorfield18:01:39

If you read the justification for the next.jdbc.sql stuff, it exists primarily as a migration aid from clojure.java.jdbc -- the recommended approach is to use the next.jdbc functions and a DSL like HoneySQL if you don't want to write SQL strings.

seancorfield18:01:55

In clojure.java.jdbc, insert-multi! took a series of hash maps but under the hood it did repeated single row inserts.

seancorfield19:01:27

The array form of arguments -- a row of column names follow by rows of data -- was the only way with c.j.j to get a single batch operation.

seancorfield19:01:56

But also note the caveats about database-specific behavior around that...

seancorfield19:01:57

(BTW, I'm more likely to see questions about next.jdbc or clojure.java.jdbc in the #sql channel since it's much lower traffic than #beginners or #clojure -- and there's a #honeysql channel too, if you have questions about that @parkerjohnsonwebdev)

Parker19:01:07

gotcha! That makes a lot of sense now that I'm reading this. Thank you very much for the explanation

seancorfield19:01:10

The database-specific behaviors drive me crazy, especially since the workarounds and JDBC connection options differ between databases 😞

Parker19:01:05

yeah that's gotta be an incredible pain for you

Hagenek19:01:13

Hi everyone. I am trying to add the time library. I have added this to the namespace in my core.clj file: (ns clojure-noob.core

(:require [clojure.data.json :as json])
  (:require [clj-time.core :as t]
            [clj-time.format :as f])
  (:gen-class))
and this into my deps.edn which is located in my project folder:
{:paths ["resources" "src"]
 :deps {org.clojure/clojure   {:mvn/version "1.10.1"}
        org.clojure/data.json {:mvn/version "0.2.7"}
        http-kit              {:mvn/version "2.4.0-alpha4"}
        cheshire              {:mvn/version "5.9.0"}
	clj-time 	      {:mvn/version "0.14.2"}}
I can get it to work the clojure repl in the terminal, but not in the ciderREPL in emacs.

Nate Sutton19:01:32

is your cider old?

dpsutton19:01:59

can you eval (ns-aliases *ns*)?

Hagenek19:01:44

returns {}

dpsutton19:01:46

then there's no t namespace

Hagenek19:01:20

ELI5, Clojure is my first language. Does not this set a namespace as t? Screenshot 2020-01-25 20.58.23

dpsutton20:01:41

put them all in the same require

dpsutton20:01:06

(ns blah
  (:require [thing :as t]
            [thing2 :as t2]
            [thing3 :as t3]))

Hagenek20:01:18

Still getting error when I try to compile: Screenshot 2020-01-25 21.09.44

hiredman20:01:19

You removed the vector around the sub clause for clojure.data.json between your two screenshots

Hagenek20:01:12

Wow now I felt stupid, it’s the par-edit which I still mess up with. I got it to compile now, but its still the same error:

Syntax error compiling at (clojure_noob:localhost:51835(clj)*:43:25).
No such namespace: t

Matti Uusitalo20:01:57

Can you try to require the namespace straight in the repl? This should isolate the source of the problem a bit.

Matti Uusitalo20:01:15

(require '[clj-time.core])

Hagenek20:01:49

Execution error (FileNotFoundException) at clojure-noob.core/eval6269 (form-init5163200568704381030.clj:52).
Could not locate clj_time/core__init.class, clj_time/core.clj or clj_time/core.cljc on classpath. Please check that namespaces with dashes use underscores in the Clojure file name.

Matti Uusitalo20:01:01

Did you launch the cider repl before adding clj-time to the deps.edn? Maybe you need to close and restart the repl

hiredman20:01:03

I bet you are starting your cider repl using a tool that doesn't support deps.edn

Hagenek20:01:12

Fixed it now, by adding

:dependencies [[org.clojure/clojure "1.10.0"]
                 [org.clojure/data.json "0.2.6"]
                 [cheshire "5.9.0"]
                 [clj-time "0.14.2"]]
in the project.clj

hiredman20:01:46

Deps.edn and project.clj are used by entirely separate tools

Hagenek20:01:11

I am using emacs

Matti Uusitalo20:01:18

Cider should support both

hiredman20:01:28

Emacs is an editor

hiredman20:01:01

Project.clj is used by lein and deps.edn is used by clj

hiredman20:01:34

Typically you only really need one or the other depending on if you are using lein or clj

Matti Uusitalo20:01:28

Ah. If you have both files in the project folder, cider probably defaulted to using leiningen

Hagenek20:01:59

Then I will continue using the leining and project.clj

andy.fingerhut21:01:13

Just as a slight additional detail on there, which you do not necessarily need to understand at this moment, but long term is useful: a single library described in a project.clj file (or deps.edn file) can contain multiple Clojure namespaces. Often the namespaces inside of a library have similar names to the library, but often they are different. In Clojure you use require and give it the name of one or more namespaces to require.

👍 1
Hagenek20:01:13

Wow this actually made me understand libraries. :as gives you shorter and more intuitive names to call all the functions contained within a library. Libraries are added in the project.clj file, and automatically downloaded. Seems so simple now that I got it working. Thank you for the help! Now onto getting data from an open API.

cljs 5