Fork me on GitHub
#beginners
<
2021-05-04
>
zackteo03:05:06

Hello, asking this in attempts to get a Java library working in 100% clojure. Is there a way to do type hinting to specify something like List<Room> or java.util.List<optaplanner_clj.data.Room>

zackteo03:05:24

Like I need to return a property as a typed Collection. Or are generics indeed being erased at runtime

alexmiller04:05:24

They are erased and there is no way to say that in Clojure

zackteo04:05:51

Alright! Thanks! Shall see if there's another way around it :thinking_face:

FHE04:05:28

2 quick questions: I'm trying to decide whether to try figwheel-main or shadow-cljs, and I'm leaning toward shadow because supposedly if I want to do mobile down the road (after getting decent at web, or to make the web things I make also work on mobile) shadow is supposed to make that easy. 1. How much truth is there to that? 2. Why is Java a dependency of shadow-cljs?? (Is it because it handles not just ClojureScript, but also Clojure (for the server side of things)? ...but if it uses Node.js, doesn't that mean the server side would be in JS (CLJS)??)

wilkerlucio04:05:25

hello, the way in which Shadow will make a lot of things easier than Figwheel is related to NPM deps, with Shadow you can add almost any NPM dependency directly, this don't work this way out of the box with Figwheel. About the Java dep, that's because Clojurescript is written in Clojure, which requires the JVM, both Shadow and Figwheel will require Java to compile

raspasov04:05:08

@U066U8JQJ that’s not true anymore, at least for React Native development (haven’t tried browser in a while) it does work out of the box as of last year

raspasov04:05:39

(talking about adding NPM dependencies)

wilkerlucio04:05:48

I know CLJS add the bundle version option, that requires an external bundler like Webpack, did this changed on the Figwheel side?

wilkerlucio04:05:42

ah, for React Native you are running in the Node environment, so require just works there, I guess that's why you can use figwheel + NPM there

wilkerlucio04:05:04

but for browser, no luck on Figwheel afaik for npm deps

raspasov04:05:33

Also with React Native you must still use the metro bundler which is part of the “regular” RN workflow. If you’re doing browser dev, shadow-cljs would actually save you from using an extra bundler, so that’s nice there.

FHE04:05:27

Must still use the metro bundler...for which? figwheel or shadow? Sorry, lost track there.

FHE04:05:02

...but it essence if I want to do web for sure and mobile probably, then shadow-cljs sounds best (for a noob)?

FHE04:05:53

@U066U8JQJ I did do the first part of the ClojureScript Quick Guide, and that ran. I had installed Java (started following the Clojure Getting Started page and then thought "no wait...don't need this since CLJS based on JS). I was wrong, obviously, but I never got to the point of setting the JAVA_HOME variable but the CLJS quick guide part I did still worked. Is it important to set it anyway?

FHE04:05:05

(Not sure how to do that. Conflicting accounts on the web.)

wilkerlucio04:05:48

the metro thing @raspasov said is something specific for React Native develop, unless you are doing that, no need to worry about it

👍 3
wilkerlucio04:05:04

I never set JAVA_HOME too, if you OS can find java and compile without it, its fine

FHE04:05:07

OK, great (about the variable). Even though I think it's right near the top of the Clojure Getting Started write-up! 😛

FHE04:05:01

As far as React Native, well I'm 90% sure I'll want to do mobile soon enough. Just trying to pick the best option (shadow.cljs vs figwheel-main) knowing that in advance. Based on minimizing/easing whatever slew of extra tools I would have to learn at that point with for each option.

raspasov04:05:55

@factorhengineering I haven’t used shadow-cljs, but many people are happy with it so I assume it’s a pretty good option.

raspasov04:05:50

metro is specific to React Native, nothing to do with figwheel or shadow-cljs, yes

FHE04:05:31

OK. Good to know. So no reason to think either option is better from your perspective?

FHE04:05:39

That shadow easing mobile thing must have been a dumb rumour.

FHE04:05:52

I'm still going to try it only because I tried it on my previous (failed/abandoned 😞 ) go-around months ago when I tried setting everything up for dev entirely from Windows (no WSL2).

FHE04:05:52

I want to see if switching to WSL2 makes it any easier for me to get going with shadow-cljs. ...change one variable at a time, you know? 🧪

wilkerlucio04:05:11

the maintainer of Shadow uses Windows, so its likely it works good there because he is on top of it 🙂 but I guess both should work fine

wilkerlucio04:05:14

I used figwheel a long time ago, but since I switched to Shadow I never looked back, there are many small things that are nice about Shadow, but the biggest and easiest selling point is easy NPM integration on the browser, just that would be enough to keep on it for me

FHE04:05:49

Whoa. That gives me a sinking feeling, actually. 😟 Not that I think it will be worse on Linux, but that now I have no reason to think I'll be any better at figuring it out. lol

FHE04:05:06

Oh well...installing node now, then taking on shadow again...

wilkerlucio04:05:04

but from a friend that was using windows before, its usually the hardest place for dev environments these days

wilkerlucio04:05:16

the others usually have a few command lines you run and everything gets working

FHE04:05:42

It is taking me days and days to put everything together, but I am taking super-detailed notes so if I ever have to set things up again I can not have to look things up in 300 different places again.

FHE05:05:19

The actual steps, though, do seem maybe a bit shorter on the Linux side.

FHE05:05:55

Wha-a-at. I remember node taking way-y-y longer to install on Windows. If it's really properly installed then this is a difference.

FHE06:05:05

@U066U8JQJ @raspasov Thank you both. It almost seems like I might be actually writing code sometime somewhat soon. 🙂

😃 9
FHE04:05:05

@seancorfield I guess you are referring to the yarn alternative to npm, which is listed in the shadow-cljs write-up as such (a viable alternative). I'm just about to start setting up shadow-cljs, and looking at that option now.

FHE05:05:55

Trying to install shadow-cljs on WSL2 Ubuntu 20.04. Dependencies Java OpenJDK and Node.JS already installed. No mention (that I can find) on the shadow-cljs github page of how to actually install it, but found, on https://docs.cider.mx/cider/cljs/shadow-cljs.html the command npm install -g shadow-cljs. Permission errors so tried sudo npm install -g shadow-cljs. Now I get npm ERR! cb() never called! npm ERR! This is an error with npm itself. Please report this error at: npm ERR! <> npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/2021-05-04T05_10_49_170Z-debug.log e

FHE05:05:18

OK, well after checking the log file and seeing nothing helpful to me, I just tried running the exact same sudo installation command again, and this time it worked. Go figure!

raspasov05:05:19

I guess that’s the same guide at http://cider.mx

FHE05:05:31

I'm reading it now. I did a web search for the http://cider.mx comment about installing it globally because I vaguely remembered that text from when I installed it on Windows months back.

Aron05:05:06

doing everything sudo might make it look like its working, but it's defnitely not necessary

FHE05:05:13

It seems really strange that the github page for shadow-cljs didn't mention how to install or point to the guide...not even in the 'Guides' section.

Aron05:05:40

I am using shadow-cljs in wsl2 ubuntu and all i did was (apart from following the guide and asking help here a lot!) that I installed shadow-cljs and then always start with shadow-clj restart (start expects clean shutdown, which with wsl is not going to happen, restart ignores previous garbage), then I use the web interface after.

FHE05:05:59

I did it without sudo first and it said (among other errors) npm WARN checkPermissions Missing write access to /usr/lib/node_modules and npm ERR! The operation was rejected by your operating system. npm ERR! It is likely you do not have the permissions to access this file as the current user npm ERR! npm ERR! If you believe this might be a permissions issue, please double-check the npm ERR! permissions of the file and its containing directories, or try running npm ERR! the command again as root/Administrator.

Aron05:05:23

yeah, so did you check the permissions?

FHE05:05:50

sudo is the only approach I know in that department. lol

Aron05:05:56

that's not a check

Aron05:05:03

ls -la usually works for me

Aron05:05:17

and you use chown and chmod to change it

FHE05:05:19

In that folder it mentioned?

Aron05:05:25

everywhere

Aron05:05:39

I would say that keeping permissions in order is the absolute must

Aron05:05:56

don't use linux or wsl if you are not doing it, that's just my opinion of course

FHE05:05:45

All new to me.

Aron05:05:56

to be clear, I check it automatically when I list directory content, and in my experience you only rarely need to actually change anything

Aron05:05:20

but since everything constantly depends on them being in order, I don't see how one can avoid it. doing everything sudo is not just that now you are constantly in superuser mode, but also everything you start will be running like that too

FHE05:05:23

I just tried navigating to the parent folder (/usr/lib/) and running ls -la. In the giant list of folders I see node_modules has drwxr-xr-x beside it.

Aron05:05:54

could be some package you installed or you ran npm install in that folder earlier

FHE05:05:02

I'm guessing that's the permissions?

FHE05:05:25

1st ever attempt at installing it.

raspasov05:05:32

@ashnur come on, I mean I get where you’re coming from but he’s just trying to get his Clojure(Script) running 🙂 You can figure out how to do perfect Linux administration later…

FHE05:05:36

Folder wouldn't have even existed before.

Aron05:05:15

@raspasov please do not misrepresent what I am saying, nothing 'perfect' or 'linux administration'

FHE05:05:24

Would really hope I wouldn't have to run an installation, have it break on a brand new folder's permissions, need me to fix the permissions somehow, and then run the installation again.

Aron05:05:59

you don't have to fix them, just clear up and try again imho

FHE05:05:32

Not sure what you mean by 'clear up' vs 'fix'.

Aron05:05:50

no need for apologies, not about my ego, i don't want anyone to waste time, being able to see things that can be trivial to avoid if one is knowledgeable about them is a big help.

👌 3
Aron05:05:23

@factorhengineering a fix would be to change the permissions of the files. but that requires intimate knowledge of everything you touch

Aron05:05:00

a clear up is when you remove what you recently added and redo the things you did, but with more foresight (or hindsight :D)

Aron05:05:38

presumably avoiding mistakes, because, and I apologize too for the assumption, but you do seem to be rushing into this whole thing 🙂

FHE05:05:14

So in this case that would be...deleting the folder the installation complained about (and that it added itself) and trying again?

Aron05:05:35

I could only confirm this if I knew better what you were doing.

FHE05:05:29

I mean I guess that could work. Even the sudo version needed two tries (with no intervening actions by me in between). Ha ha.

FHE05:05:59

All I'm doing is installing shadow-cljs with the commands above.

Aron05:05:24

well, try the guide 🙂 that's what worked for me

FHE05:05:56

Updated Windows, installed WSL2, got Ubuntu 20.04 from Windows Store, and just installed Emacs, Doom, Java, and a few of their stated dependencies and maybe a thing or two more. Pretty fresh OS.

FHE05:05:15

Definitely. Going to the guide next. 🙂

FHE05:05:19

By the way...

raspasov05:05:20

I recommend “yarn” but that’s just my experience (more reliable than “npm”)

FHE05:05:40

Since you're in WSL2 Ubuntu, do you know how to change the font colour the CLI uses for folders and paths (and comments in vim). I'm dying trying to read the horrible dark blue text on a black background.

FHE05:05:34

I tried this, which is supposed to change the actual "blue" and/or "dark blue", but it did not work: https://askubuntu.com/questions/147462/how-can-i-change-the-tty-colors

FHE05:05:37

I think maybe the reason it didn't work is because the WSL2 Ubuntu 20.04 CLI isn't 'tty' but maybe something else?

Aron05:05:36

i know what I am doing, but I don't recommend. I start this https://sourceforge.net/projects/vcxsrv/ and use gui, then start https://sw.kovidgoyal.net/kitty/https://sw.kovidgoyal.net/kitty/ and everything looks exactly the same anywhere in kitty because I have the same config copied everywhere

FHE05:05:17

I have my monitor way brighter than I want it at this time of night and I can still barely read it. I think I'm up for something drastic. HOW can this be the default???

Aron05:05:27

no one uses the default

FHE05:05:46

Ha ha ha. Helpless noobs do! It's a trap!!

Aron05:05:26

btw, what cli you are using? the new Terminal app?

FHE05:05:28

I do have vcxsrv set up. That was one of those 'other things' I installed.

FHE05:05:46

Just whatever CLI you get thrown into when you launch Ubuntu 20.04.

FHE05:05:45

OH YEAH...and another thing! I have the Terminal app, but it will not serve up WSL2 tabs. I'm almost certain it did right after I installed it, but it just doesn't feel like it anymore.

FHE05:05:51

Solving that might solve the colour issue. With any luck the default CLI colours of WSL2 are sane in Terminal.

FHE05:05:15

I'm looking at this kitty thing, but I'm sad if I can't just change a pre-existing Ubuntu config file. 😔

FHE05:05:32

Welp. I just ran Terminal yet again on a whim, and today it does feel like saying Ubuntu-20.04 tabs can exist. All this flakiness... lol

FHE05:05:48

The blue in Terminal is much better. Yay!

seancorfield06:05:20

@factorhengineering As discussed in that thread the other day, the lack of WSL2 distros in Terminal is a known bug but it’s a timing bug: it is most likely to happen if you try to start Terminal either immediately after a reboot, while Windows is still “busy” starting things up, or if you’re system is under heavy load. As noted, I also encountered that bug but only if I try to start Terminal immediately after a reboot.

seancorfield06:05:40

(and, yeah, I changed the default Terminal color scheme — can’t remember what I changed it to or whether it’s specific to the Insider builds I’m running, just FYI)

FHE06:05:36

Do you happen to know the name of the default CLI you get if you just run (WSL2) Ubuntu 20.04 (straight from the Start menu, not in Terminal?

FHE06:05:56

It's great that Terminal is finally working again (after multiple attempts throughout the day yesterday and the day before), but it would be nice to know if I can salvage the readability of the text in the CLI that reliably starts up. Ha ha.

seancorfield06:05:28

@factorhengineering it’s just a bash shell (running in a regular window).

FHE06:05:35

That http://askubuntu.com solution I found was for tty (and did not work for me).

seancorfield06:05:42

(apparently I’m using the Campbell color scheme in Terminal)

FHE06:05:31

I'm OK with the colour scheme in the Terminal CLI...though the vim comments are the same terrible blue as the default CLI and the vim in that.

seancorfield06:05:50

Code looks pretty nice in vim in Terminal with the Campbell color scheme selected, if that helps.

FHE06:05:41

How do you change the colour scheme?

seancorfield16:05:38

In the Settings menu item.

seancorfield16:05:14

(in Terminal — I do not start Ubuntu directly from the Start Menu and I’ve no idea whether you can control the colors there)

FHE21:05:36

A colour picker! Yay!

FHE06:05:53

If you run Ubuntu 20.04 from the Start menu, what is that CLI called.

FHE06:05:30

If I knew how to change the colour scheme in Terminal and that fixes the vim in Terminal, as you say, that would be great.

FHE06:05:32

Greater still would be fixing the colours (really just 'blue' and possibly 'dark blue') in the default CLI that you get when you run from the start menu. I can't do a proper search for how, though, because I don't even know what it's called. 😞

FHE06:05:41

@ashnur thanks for the help earlier. @seancorfield it's very late again so I'll have to revisit this tomorrow. Thanks to you too! If you or anyone here knows the name of the default WSL2 Ubuntu 20.04 CLI I'll read it tomorrow and scour the net for a way to add some red and green to that blue and make it readable in the CLI and in vim! 🙂

seancorfield16:05:48

As I said above “it’s just a bash shell (running in a regular window)“.

Stuart08:05:00

Can someone help me out please. I have a function

(defn macro-expand-code [code macros]
  (map (partial macro-expand-line macros) code))
macro-expand-line returns either something like: A single string:
"mov :a 2"
Or a list of strings:
("mul :a :a" "mul  :b  :b" "add :a  :b")
So I end up with
'("mov :a 2" "mov :b 5" ("mul :a :a" "mul  :b  :b" "add :a  :b") ("add :a 10"))
But I dont want the inner nesting. I thought I could use mapcat rather than map , but then I end up with:
("m" "o" "v" " " ":" "a" " " "2" "m" "o" "v" " " ":" "b" " " "5" "mul :a :a" "mul  :b  :b" "add :a  :b" "add :a 10")
The single strings get expanded out to individual string per character...

Stuart08:05:29

Nevrmind, got it! This works

(defn macro-expand-code [code macros]
  (->> (map (partial macro-expand-line macros) code)
       (flatten)))

Darin Douglass10:05:41

If you wanted to use mapcat, you would need to make macro-expand-line always return a coll (which I'd recommend over using flatten).

Stuart10:05:27

Oh yeah! That works. I just changed macro-expand-line to

(defn macro-expand-line [macros line]
  (let [macro-call (is-macro-call? (keys macros) line)]
    (if macro-call
      (expand line (macros macro-call))
      (list line)))) ; made this a list.
And now this works:
(defn macro-expand-code [code macros]
  (mapcat (partial macro-expand-line macros) code))
Thanks!

Stuart10:05:56

I do vaguely remember reading something about avoid flatten if possible

Darin Douglass11:05:55

Ya I’m almost all situations you don’t need flatten. I think the biggest problem is it delazies everything you give it, where mapcat won’t. In your situation mapcat works better IMO because it necessitates getting rid of a bug/unexpected behavior caused macro-expand-line not returning the same type all the time.

Santiago10:05:10

I’m working more extensively with atoms for the first time. I’m using them as a sort of in-mem database for a prototype to hold a map. I had lots of functions deref ing atoms to get their state. I was doing this at different points in a pipeline but then I thought this is bad because the state could change between steps. Instead, I started doing (let [current-vals @db]) at the very top and then always working with this. Now, is current-vals in this example still blocking db , or did it make a copy (a snapshot if you will) and moved on so that other threads can continue reading and writing to db ?

NoahTheDuke11:05:23

A copy. Deref ing an atom gets the persistent data structure contained inside

👍 3
chepprey23:05:15

(To be a bit pedantic for beginners) you don't get a copy because no copy is created. Deref ing an atom gives you whatever immutable value is referenced by the atom at that time.

Santiago07:05:15

hehe be pedant away @UHL84CDTP 😄 thanks! I

🤓 3
yiorgos11:05:56

Is it possible to install Java libraries from https://mvnrepository.com using tools-deps ?

delaguardo11:05:41

what do you mean under “install”?

yiorgos11:05:23

for example, I would like to use this library https://mvnrepository.com/artifact/org.geotools/gt-swing in my Clojure project

delaguardo11:05:43

normally you don’t need to “install” a library. The way to start using it is to describe that you need it in some form (normally dictated by you build tool)

yiorgos11:05:12

If I add this line under the deps alias org.geotools/gt-swing {:mvn/version "25.0"}

yiorgos11:05:23

I am getting this error Error building classpath. Could not find artifact org.geotools:gt-shapefile:jar:25.0 in central ()

yiorgos11:05:20

so next step is to add :mvn/repos {"mvn" {:url ""}}

delaguardo11:05:28

org.geotools:gt-shapefile this artifact is not a part of maven central, I think

yiorgos11:05:36

but I get a 403

delaguardo11:05:03

there is a Note

delaguardo11:05:36

so you need to add that repository instead of http://mvnrepositories.com

yiorgos11:05:55

where did you see that note 🙂

delaguardo11:05:28

I clicked on a version

yiorgos12:05:06

super! thank you very much!!!

Endre Bakken Stovner15:05:17

Does anybody want to take a stab at guessing what https://gist.github.com/endrebak/ac84a7a8a44e57bd7f14d0251a688e64 might be due to?

Endre Bakken Stovner15:05:13

I'm trying to set up a Clojure development on my new M1 Mac. That is the error I get when I try to lein run the code I'm currently working on.

hiredman16:05:43

you have a user.clj file that is calling everclear.dag.core/file-to-map which is calling slurp on nil

hiredman16:05:20

% clj
Clojure 1.10.2
user=> (slurp nil)
Execution error (IllegalArgumentException) at user/eval1 (REPL:1).
Cannot open <nil> as a Reader.
user=>
%

Endre Bakken Stovner05:05:26

I gzipped the entire folder when moving the code to my new machine so I thought the error could not be due to missing files. Also, it said compile error so I thought it wasn't due to things happening when my code was running. So these lines mean it happened in my user.clj file? [user$eval42029 invokeStatic "form-init16520803458208972728.clj" 1] [user$eval42029 invoke "form-init16520803458208972728.clj" 1] Thanks, I actually learned a lot. It is also the first time I've seen a stack trace like that so I imagined it had something to do with my new Clojure version having failed to install properly or something.

GGfpc18:05:42

So I'm having some trouble making an HTTP GET to the IMDB API due to an SSL problem. I have no idea how to fix this, can someone give me a hand?

(let [url ""]
    @(http/get url ))
=>
{:opts {:method :get, :url ""},
 :error #error{:cause "Unrecognized record version (D)TLS-0.0 , plaintext connection?",
               :via [{:type javax.net.ssl.SSLException,
                      :message "Unrecognized record version (D)TLS-0.0 , plaintext connection?",
                      :at [sun.security.ssl.SSLEngineInputRecord bytesInCompletePacket "SSLEngineInputRecord.java" 98]}],
               :trace [[sun.security.ssl.SSLEngineInputRecord bytesInCompletePacket "SSLEngineInputRecord.java" 98]
                       [sun.security.ssl.SSLEngineInputRecord bytesInCompletePacket "SSLEngineInputRecord.java" 64]
                       [sun.security.ssl.SSLEngineImpl readRecord "SSLEngineImpl.java" 605]
                       [sun.security.ssl.SSLEngineImpl unwrap "SSLEngineImpl.java" 499]
                       [sun.security.ssl.SSLEngineImpl unwrap "SSLEngineImpl.java" 475]
                       [javax.net.ssl.SSLEngine unwrap "SSLEngine.java" 634]
                       [org.httpkit.client.HttpsRequest doHandshake "HttpsRequest.java" 98]
                       [org.httpkit.client.HttpClient doRead "HttpClient.java" 193]
                       [org.httpkit.client.HttpClient run "HttpClient.java" 494]
                       [java.lang.Thread run "Thread.java" 830]]}}

borkdude18:05:02

@ggfpc12495 Are you using the SNI client?

GGfpc19:05:47

(alter-var-root #'org.httpkit.client/*default-client* (fn [_] sni-client/default-client))
I have this line in my file, but the result is the same

GGfpc19:05:57

Should it be somewhere in specific?

borkdude19:05:14

@ggfpc12495 Can you try it with bb maybe?

bb -e '(:body @(org.httpkit.client/get ""))'

borkdude19:05:17

that works for me

GGfpc19:05:56

works for me too

GGfpc19:05:58

that's weird

GGfpc19:05:35

of figured it out

GGfpc19:05:50

I had a java property that disabled SNI from a previous experiment, so the SNI client wasn't doing anything

borkdude18:05:37

I think this should be enabled by default, there is an issue for this

Karo19:05:32

Hello team, it seems that it is not possible to convert string into json if there is a string in the string as shown below, is there any way to convert this string into json?

(json/read-str "{\"testing this \"hhh\" next\" :1,     \"b\" :2}")

dpsutton19:05:09

(json/generate-string {:key "value contains a \"string\""}) check what valid JSON looks like if it contains a string

👍 3