Fork me on GitHub
#beginners
<
2023-03-19
>
deepak kumar03:03:11

Hi team, I'm new to clojure and started learning it via practicing syntax and problems online. I'm trying to setup clojure in my project in windows system, I've set path variable of lein.bat file in environment variable but it seems not working, I have to add lein.bat file in every project folder to get run it. Error: LSP classpath lookup failed when running lein with-profile +test,+dev classpath. Some features may not work properly if ignored. Error: Cannot run program "lein" (in directory "C:\Users\DEEPAK KUMAR\tutorial"): CreateProcess error=2, The system cannot find the file specified Choose an option: Please, If anyone knows what I am missing let me know.

nitin05:03:43

You should use https://scoop.sh/ to install clojure (https://github.com/littleli/scoop-clojure) as well as https://scoop.sh/#/apps?q=lein&amp;s=0&amp;d=1&amp;o=true (also, can install jdk if haven't via scoop scoop install temurin-lts-jdk), as it sets environment variables on it own, works like apt in unix. Then, it will work, without any issues.

seancorfield05:03:30

Another option is to use the (fairly new) MSI installer: https://github.com/casselc/clj-msi/releases/tag/1.11.1.1252 -- this will give you the Clojure CLI, without needing to install a package manager like Scoop.

nitin06:03:35

Big fan here Sir @U04V70XH6 of your blog (https://corfield.org/). I just wanna say the https://github.com/casselc/clj-msi#clojure-installer installs the same https://github.com/borkdude/deps.clj, so choose either way @U04UD707R62 it will work, package manager version is more recent updated 1.11.1.1257 and updates are easy and automated via cli, whereas in msi you gotta do the manual work to download and install.

deepak kumar14:03:28

@U04V70XH6 It worked sir, thanks a lot.

Gutierre03:03:39

You need to add lein into your path.

deepak kumar04:03:04

into Environment variable right? if it is this, I've added.

deepak kumar04:03:54

I've added it in c drive inside a lein folder, folder name : lein contains lein.bat file.

seancorfield05:03:46

Do you have C:\lein in your PATH variable? That's where it needs to be added. You don't need a variable called lein.

deepak kumar06:03:56

in c drive I have made a new folder named lein, inside that I have inserted lein.bat file, sir.

deepak kumar04:03:21

Anyone who is learning and building in clojure in windows operating system. I need some help in setting it up the environment for clojure.

nitin05:03:35

I replied in your first message, uninstall all your clojure setup and follow those steps, it will work.

deepak kumar05:03:18

Thank you buddy, will update after doing the stuffs.

Rob Haisfield22:03:03

I’d like to use the LangChain TypeScript library in ClojureScript, and get useful typehints. Has anyone written or created a guide to interop? I know about JavaScript interop, but I’d like to still use the types.

Jakub Šťastný22:03:12

How do I get current year and month?

(.getYear (new java.util.Date))
; => 123
Year 123? Have we gone to the past? Besides the method seems to be deprecated https://docs.oracle.com/javase/8/docs/api/java/util/Date.html I don't speak Java and the Java documentation is appalling. Can someone please point me in the right direction? (Obviously I'd prefer Clojure, but I don't believe there's anything that'd be built-in, correct me if I'm wrong.)

tomd22:03:08

To explain that result see this in your link: > A year y is represented by the integer y - 1900.

👍 2
Jakub Šťastný23:03:12

That's horrifying that you need to read doc for something like "get me current year". It should just give the current year as int, what else? Glad I never did Java 🙈

😂 4
pavlosmelissinos23:03:21

(import [java.time Year])
  (.getValue (Year/now))

👍 2
pavlosmelissinos23:03:30

tick and java-time are nice Clojure wrappers if you work a lot with time (or plan to target multiple runtimes) but you don't need a middle-man for simple stuff like this imho. Just interop with java.time.

👍 2
Jakub Šťastný23:03:32

(.getValue (Year/now)) works, but I can't figure out how to get month from it.

Jakub Šťastný23:03:53

I found there's also java.time.Month, but it has no now.

pavlosmelissinos00:03:45

What are you trying to achieve? Perhaps there's a better way

Jakub Šťastný00:03:28

(defn current-month []
  #?(:clj
     (let [date (new java.util.Date)]
       (make-date (.getValue (java.time.Year/now)) (+ (.getMonth date) 1)))
     :cljs
     (let [date (new js/Date)]
       (make-date (.getFullYear date) (+ (.getMonth date) 1)))))

Jakub Šťastný00:03:49

Essentially make-date just returns {:year y :month m} and I use that map (and a few fn to manage it to work with dates, since I have no need for days, TZs etc. Besides it makes it platform-independent.

pavlosmelissinos00:03:28

(import [java.time LocalDate])

  (defn current-month []
    #?(:clj
       (let [date (LocalDate/now)]
         (make-date (.getYear date) (.getMonthValue date)))
       :cljs
       (let [date (new js/Date)]
         (make-date (.getFullYear date) (inc (.getMonth date))))))
This is one way to do it edit: fixed month; java.time doesn't need the +1 adjustment

👍 2
pavlosmelissinos00:03:15

1. java.util uses Joda time which is deprecated, you should avoid it 2. Can't tell from this snippet but if you want to extensively target JVM and browsers you should take a look at cljc.java-time or tick 3. if make-date builds a date string, you can use a formatter to build it, there's probably no need to write your own function

Jakub Šťastný00:03:03

Oh that's brilliant, cheers @UEQPKG7HQ!

Jakub Šťastný00:03:43

It doesn't build a string, it just returns that map and I have various simple methods to do (current-month {:year 2023 :month 12}) etc, also converting it to an int so you can do arithmetics on it or comparison etc.

👍 2
Jakub Šťastný00:03:56

Nothing fancy, just wanted to get rid of the complexity of dates.