Fork me on GitHub
#beginners
<
2020-08-02
>
Flavio Barros13:08:01

Hello all! I am a beginner and I'm having a hard time with clojurescript and lein.

Flavio Barros13:08:03

I just installed everythin, lein is working with a vanilla clojure project, I can access repl, but when I start a new project with figwhell I can't run it. I created a project with:

Flavio Barros13:08:34

lein new figwheel my-web -- --reagent

Flavio Barros13:08:53

and after that entered my-web and installed all js dependencies

Flavio Barros13:08:23

lein figwheel

Flavio Barros13:08:35

I receive the following error:

Flavio Barros13:08:02

Figwheel: Cutting some fruit, just a sec ... Figwheel: Validating the configuration found in project.clj Figwheel: Configuration Valid ;) Figwheel: Starting server at Figwheel: Watching build - dev Compiling build :dev to "resources/public/js/compiled/out/index.js" from ["src"]... Failed to compile build :dev from ["src"] in 1.547 seconds. ---- Exception ---- clojure.lang.ExceptionInfo : :build-cmd :none failed .IOException : Cannot run program "npx": error=2, Arquivo ou diretório inexistente .IOException : error=2, Arquivo ou diretório inexistente

nick14:08:29

Is npx installed? If not you may need to try sudo npm i -g npx Your questions sounds like it rather belongs to #clojurescript or #figwheel channel instead. Try asking there instead if npm i didn't work.

nick14:08:10

Also, I'm a bit biased on this one but you can probably give luminus template a try instead of "figwheel" template. There is a chance that's it is more up to date. https://github.com/luminus-framework/luminus-template there is "+cljs" profile hint as well

Flavio Barros03:08:35

thank you @U0113AVHL2W I am still finding my way over these tools. But from my research maybe shadow-cljs should be easier to work with. I gave up on this

Flavio Barros13:08:20

but I didn't anything. Should be working right???

Flavio Barros13:08:14

My lein version: Leiningen 2.9.4 on Java 11.0.7 OpenJDK 64-Bit Server VM

nick14:08:30

Is there a method to stub a function in java.lang.System ns? "exit" to be exact Attempted this snippet:

(with-redefs-fn [java.lang.System/exit (fn [x] (println "stubbed exit with status code" x))]
    (java.lang.System/exit 0))
It fails with: > Unable to find static field: exit in class java.lang.System The original motivation is to stub "exit" call in third-party package while I'm using it from REPL? That's cljfmt

andy.fingerhut18:08:35

I may not be familiar with how you are using the word “stub” here. You want to redefine the behavior of the Java exit method?

andy.fingerhut18:08:11

If so, Clojure does not provide a way to redefine JVM methods

andy.fingerhut19:08:08

With-redefs-fn is for redefining Clojure functions, not Java methods

andy.fingerhut19:08:47

I do not know if the JVM’s exit method is possible to redefine, or if so, how one might do it

andy.fingerhut19:08:19

The JVM documentation for the exit method mentions shutdown hooks, with a link to a method that allows you to add shutdown hooks, which appear to be called shortly before the JVM actually exits, but after exit is called

nick19:08:12

@U0CMVHBL2 thank you! 🙏

bronsa14:08:21

you can only redef vars, not methods/fields

nick14:08:06

This one seems to worked fine for stubbing a method:

(with-redefs [cljfmt.main/exit (fn [x] (println "aborting exit: " x))]
    (#'cljfmt.main/check '("/tmp/delete/project.clj") cljfmt.main/merge-default-options))
> :profiles/test {}}) > 1 file(s) formatted incorrectly > aborting exit: {:okay 0, :incorrect 1, :error 0}

bronsa14:08:46

that's a var

λraulain20:08:27

This portion of the Clojure docs doesn't seem very clear to me

;; What is inside the (commment ...) is readable, so no error for this,
;; and no code will be generated by the compiler.
(comment
(defn foo [x]
  (inc x))
)

;; What is inside the (comment ...) is NOT readable, so this will give an error
(comment
a : b
)
Is there really a (commment ...) form (with 3 m) or is that just a typo?? https://clojuredocs.org/clojure.core/comment

Alex Miller (Clojure team)20:08:09

just fyi, clojuredocs is a community web site with community submitted examples, not official documentation

👌 3
λraulain20:08:34

oh okay. thanks @alexmiller 🙏

Alex Miller (Clojure team)20:08:28

it's mostly very helpful :)

λraulain20:08:49

I guess I can just find the repo on github and fix that then simple_smile

Alex Miller (Clojure team)20:08:57

you can probably file an issue there

👍 3
Michael W23:08:18

How do a create a date inst programattically? (let [s "1980-01-01"] #inst s) Syntax error reading source at (REPL:2:10). class clojure.lang.Symbol cannot be cast to class java.lang.CharSequence (clojure.lang.Symbol is in unnamed module of loader 'app'; java.lang.CharSequence is in module java.base of loader 'bootstrap')

chucklehead00:08:29

here I think you could either do (let [s #inst "1980-01-01"] s) or (let [s "1980-01-01"] (clojure.instant/read-instant-date s)

Michael W00:08:45

Thanks read-instant-date was what I needed