Fork me on GitHub
#beginners
<
2019-07-01
>
PaulGureghian01:07:59

I try this socket setting and it won't connect. its the lein repl, which i have started already.

seancorfield02:07:04

You can't connect Chlorine to an nREPL server, only a Socket REPL.

andy.fingerhut02:07:23

nREPL and socket REPL have a lot in common in their names, but are not the same thing.

seancorfield02:07:58

You can tell Leiningen to start a Socket REPL. I have this profile in my ~/.lein/profiles.clj file

:socket {:jvm-opts ["-Dclojure.server.lein={:port 55555 :accept clojure.core.server/repl}"]}

seancorfield02:07:10

(`profiles.clj` is a hash map of profiles)

seancorfield02:07:01

Then you can start Leiningen with that profile added:

lein with-profile +socket repl
and that will start a REPL, with an nREPL Server (which is default Leiningen behavior), but also a Socket REPL on port 55555.

👍 4
seancorfield02:07:11

Then you can connect Chlorine to that Socket REPL

PaulGureghian02:07:41

thats on my todo list

seancorfield02:07:51

That's what I use when I'm working on a Leiningen-based project, so I can continue using Chlorine as normal.

PaulGureghian02:07:55

Seems better now. two questions though: when I make and edit, i always get a 'failed to refresh' message, is this just something to get used to ? and shouldnt one of the outputs eval to even ?

andy.fingerhut02:07:21

Which right paren matches up with the left paren just before the cond in that code?

andy.fingerhut02:07:39

That is where the cond expression ends.

seancorfield02:07:18

Re: failed to refresh. Make sure your Settings for the Chlorine package look like this...

seancorfield02:07:01

Well, you can have the console position be right (like you seem to have it set now).

seancorfield02:07:48

The important one is the last one. Make sure refresh on save is off and change the refresh mode to simple

seancorfield02:07:16

@paulgureghian @andy.fingerhut is right -- your parens are messed up. Your cond ends with the ) after "even" and then your function contains two more expressions -- the (= (rem n 2) 1) expression and finally the "odd" expression -- so your function always returns "odd" because that's the last expression in your function.

seancorfield02:07:07

If you install Parinfer it will help you balance your parens better.

Schmoho11:07:51

Hey! I was just reading some cheshire-code and got somewhat confused. The function generate-string in the core-ns has typehints ^String on its argument-vector. What is the rationale there? The function is explicitly for json-stringifying arbitrary clojure-objects, so why typehint it as String?

Schmoho14:07:41

I see, that makes sense

dangercoder12:07:42

Regarding Clojurescript and Javascript, doesn't hot reloading in Javascript work as good as in Clojurescript (Year 2019?). Aka when you change some code the state remains the same (if you use something like React + Redux?). I haven't done any javascript since the jquery days.

dangercoder12:07:12

I know that Clojurescript had support for this before javascript through figwheel.

Crispin12:07:35

I find the difference is in whats idiomatic. Yes, with the right javascript code using the right datastructurescoded in the right way it can work. But in cljs that way is much more idiomatic. Any code you are depending on has been built around the proceeds of time constructs... because thats the only way in cljs. In javascript it feels like fighting. In cljs it feels like flow. Just my opinion, of course. Javascript fans may disagree.

mfikes12:07:49

The thing I'm curious about is whether it pans out in JavaScript if you don't have immutable data nor a single app state atom. I would imagine that things could get out of hand if references to mutable data end up spread throughout your app while you are trying to update it, but I'm only speculating and am honestly curious. Perhaps this is what @UKH2HDSQH is referring to: Things can work with extra discipline.

Crispin12:07:40

I'm not a great js programmer, but when I have done react and redux and state management, I'm always accidentally breaking it. Like, whoops, that code mutated the state in place, not created and returned a new state. And it doesnt throw an error. It just subtley misbehaves. And then I'm trying to find the needle in a haystack. In cljs, for me, it just seems to work by default.

mfikes12:07:26

I wonder if this is the strange kind of stuff James Long was referring to in this tweet https://twitter.com/jlongster/status/1145507023423004672 Seems that if mutable stuff is part of the game, things can get wonky fast.

dangercoder12:07:44

would I get some more responses if I asked this question on Clojureverse? This is really interesting. 🙂

Crispin13:07:04

I also think that hotloading in cljs has improved over the last few years. I use figwheel and have found some issues have been resolved and the error reporting has definitely improved. Perhaps cljs hotloading is more mature? I don't have enough experience with the js side to say. Im using figwheel all the time.

jakuzure13:07:37

hi, is it possible to run shadow-cljs on a server and access the web page via a browser on another computer? I read about setting :http somewhere, but couldn't really get it to work. would be great for experimenting

Crispin13:07:23

not sure exactly with shadow-cljs, but the idea is bind the websocket listener (server side) to 0.0.0.0 (all interfaces) not 127.0.0.1 (localhost)

jakuzure13:07:55

I'll try that out, thank you!

thheller15:07:42

this shouldn't require any configuration? you just start the shadow-cljs process regularly and then access it via the IP. eg.

Schmoho14:07:35

This feels somewhat insane to me, with nested anonymous functions and all ... is there a more straightforward way of doing this? (I'm http/getting some json-serialized sql-dates here)

(let [parsed-response (->> (:body response)
 (.parse js/JSON)
 (map #(js->clj % :keywordize-keys true))
 (map #(update-in % [:datum] (fn [dstr] (js/Date. dstr)))))] ...)

tavistock14:07:56

#(update-in % [:datum] js/Date.) might work, it doesnt look to bad to me as is. You could make the inner anon a named fn (defn parse-date [dstr] (js/Date. dstr))

Crispin16:07:38

you can also have only one map, and thread the functions together in the map fn:

(->> ...
    (map #(-> %
              (js->clj :keywordize-keys true)
              (update :datum (fn [s] (js/Date. s))))
    ...)

dpsutton14:07:31

can you use the multiline code block? It's three backticks, code, then three backticks to close it

4
Schmoho14:07:44

Also I have the following nooby-problem: the code uses re-frame, which pulls in reagent which pulls in hiccup - so I assumed I should be able to require hiccup in the repl, but "no such namespace, could not locate", and indeed, finding and grepping on the project were quite pointless

Ahmed Hassan14:07:40

Hiccup is Clojure library.

lilactown17:07:58

@d.eltzner reagent doesn’t use the hiccup library, but instead implements it’s own parser for hiccup-like forms

dl17:07:07

hey guys

dl17:07:10

how is it going?

dl17:07:31

is there a way to make use of websockets with datomic?

dl17:07:34

Datomic Cloud

lilactown17:07:12

probably a better question for #datomic but AFAIK no

PaulGureghian19:07:39

If some owner of a small startup asked you to develop a Clojure app for demo purposes, would you do it ?

PaulGureghian19:07:16

Demo to show to potential clients

Sam Ferrell21:07:19

am I being paid by this startup owner to create said demo

PaulGureghian21:07:17

No. not for the demo, maybe after the potential client signs a contract and gets his deliverables

Pick Feky21:07:38

maybe prototype with partnership contract before making it.

PaulGureghian22:07:18

If an app is written in Python and I want to deploy said app to Heroku, do I need a Python runtime or can I opt for a Clojure runtime ?

andy.fingerhut22:07:14

I don't know any ways that a Clojure runtime will be able to do much with Python source code, nor compiled .pyc files, unless you have a very special Clojure or Java library that does something useful with them.

andy.fingerhut22:07:50

Someone has done work recently to make calls out from a JVM into a Python runtime, in order to take advantage of more Python libraries from a Clojure program, but it is pretty new stuff, and I don't know of its limitations. I am pretty sure it requires both appropriate Clojure and Python installations on the machine where it runs.

Ville Vuorinen22:07:21

guys. Whats wrong with this?

seancorfield22:07:04

@ville What error do you get?

Ville Vuorinen22:07:27

Caused by: java.lang.ClassNotFoundException: http://clojure.java.io

Ville Vuorinen22:07:54

do I need some libs or something

seancorfield22:07:01

How are you running that code?

seancorfield22:07:46

And that code is in src/test/core.clj ?

Ville Vuorinen22:07:05

and I added to project.clj :main test.core)

seancorfield22:07:44

Compare your project.clj to this

(! 619)-> cat project.clj 
(defproject test "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url ""
  :license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
            :url ""}
  :dependencies [[org.clojure/clojure "1.10.0"]]
  :main test.core
  :target-path "target/%s"
  :profiles {:uberjar {:aot :all}})

Mon Jul 01 15:14:09
(sean)-(jobs:0)-(~/clojure/test)
(! 620)-> cat src/test/core.clj 
(ns test.core
  (:require [ :as io]))

(defn -main
  "I don't do a whole lot ... yet."
  [& args]
  (println "Hello, World!"))

Mon Jul 01 15:14:17
(sean)-(jobs:0)-(~/clojure/test)
(! 621)-> lein run
Hello, World!

Mon Jul 01 15:14:24
(sean)-(jobs:0)-(~/clojure/test)
(! 622)-> 

seancorfield22:07:07

(that was just auto-generated with lein new app test -- and then I edited project.clj to have the exact same :main as you said and core.clj to remove the (:gen-class) and add the (:require ,,,) you had)

andy.fingerhut22:07:38

Just noticed that the first line (ns test.core) has a right paren that ends the ns form. You should remove that, and put the right paren that ends the ns form later.

👍 4
andy.fingerhut22:07:13

You already have a right paren at the end of your second line that will match the (ns if you delete the one at the end of your first line.

seancorfield22:07:15

Oh, good catch!

seancorfield22:07:06

So Clojure was reading it as

(ns test.core) ; complete and valid

(:require [ :as io]) ; tries to resolve  as a symbol and fails

andy.fingerhut22:07:11

The parentheses (almost) become invisible after a while, so we often don't even check them, without an editor to help us.

theeternalpulse16:07:24

I think the creator of magit made a package that makes them actually invisible

seancorfield22:07:32

And with that indentation, I didn't notice things don't match.

seancorfield22:07:05

@ville What editor are you using? You might want to add something that tracks parens and indentation/structure -- something like parinfer.

Ville Vuorinen22:07:29

I used vscode with clojure plugin

Ville Vuorinen22:07:01

I’m not sure if my repl integration works as intended.

seancorfield22:07:11

I'd recommend Calva if you're using VS Code. There's also a #calva-dev channel if you need help with it.

calva 8
Ville Vuorinen22:07:15

it works now, thanks guys.

4
calva 4