beginners

Getting started with Clojure/ClojureScript? Welcome! Also try: https://ask.clojure.org. Check out resources at https://gist.github.com/yogthos/be323be0361c589570a6da4ccc85f58f.
solf 2021-05-03T00:14:40.449400Z

I have, but can't really help you... Forgot about it and I'm not on a windows anymore. However I've heard that wsl2 finally got a gui update, this means vcxsrv shouldn't be needed anymore. More info here: https://github.com/microsoft/wslg https://www.google.com/amp/s/www.techrepublic.com/google-amp/article/linux-on-windows-this-new-upgrade-allows-you-to-run-graphical-apps-simply-and-effectively/

FHE 2021-05-03T00:42:11.449900Z

Wow. After hours of combing through info on what X11 is and how to get VcXsrv working. LOl

FHE 2021-05-03T00:42:14.450100Z

Thanks!

FHE 2021-05-03T00:43:29.450300Z

When I try to run the Quick Start Guide hello world program on the ClojureScript website, though, I get the following error:

FHE 2021-05-03T00:43:35.450500Z

`clj --main cljs.main --compile hello-world.core --repl WARNING: When invoking clojure.main, use -M Failed to launch a browser: No X11 DISPLAY variable was set, but this program performed an operation which requires it. You can instead launch a non-browser REPL (Node or Nashorn). You can disable automatic browser launch with this REPL option :launch-browser false and you can specify the listen IP address with this REPL option :host "127.0.0.1" Waiting for browser to connect to http://localhost:9000 ... ClojureScript 1.10.758`

FHE 2021-05-03T00:44:27.450700Z

clj --main cljs.main --compile hello-world.core --repl WARNING: When invoking clojure.main, use -M Failed to launch a browser: No X11 DISPLAY variable was set, but this program performed an operation which requires it. You can instead launch a non-browser REPL (Node or Nashorn). You can disable automatic browser launch with this REPL option :launch-browser false and you can specify the listen IP address with this REPL option :host "127.0.0.1" Waiting for browser to connect to <http://localhost:9000> ... ClojureScript 1.10.758

FHE 2021-05-03T00:45:16.450900Z

...and actually, after completing set-up of VcXsrv, I'm getting the exact same error...as if I wasted the last few hours. ๐Ÿ˜•

FHE 2021-05-03T00:46:15.451100Z

Just need to find out about this X11 DISPLAY variable I guess...or find some way to force WSL2 to use the newfangled feature you mentioned, @dromar56

FHE 2021-05-03T00:48:38.451300Z

...or is there a chance the Ubuntu 20.04 that goes into WSL2 doesn't even have any graphical browser (or any browser), and that's yet another thing I have to install?

FHE 2021-05-03T01:05:18.451600Z

OK, so I think I've set my DISPLAY variable correctly, and now I get a different error upon running

FHE 2021-05-03T01:05:31.451800Z

clj --main cljs.main --compile hello-world.core --repl

FHE 2021-05-03T01:05:37.452Z

error:

FHE 2021-05-03T01:05:59.452200Z

Failed to launch a browser: The BROWSE action is not supported on the current platform!

seancorfield 2021-05-03T01:07:48.452400Z

@dromar56 That is only available in Insider builds of Windows right now (that's what I'm running). @factorhengineering and I already had this exact discussion yesterday (or the day before).

seancorfield 2021-05-03T01:09:23.452600Z

Unfortunately, since I updated to the latest WSL2 with Wayland/X11 support builtin, I've forgotten what I used to have DISPLAY set to (you need it on the standard WSL2 setup, but not on the new Wayland version).

seancorfield 2021-05-03T01:09:57.452800Z

Sounds like you've figured it out @factorhengineering -- now you need a browser installed on Liinux.

seancorfield 2021-05-03T01:10:19.453Z

Was it DISPLAY=:1 in the end?

seancorfield 2021-05-03T01:12:16.453200Z

I think you should be able to sudo apt install google-chrome or something like that. That's the browser I have installed on WSL2/Ubuntu and it's what starts up automatically when I run a ClojureScript setup...

FHE 2021-05-03T01:33:27.453400Z

DISPLAY got set to an IP address with a trailing :0

seancorfield 2021-05-03T01:35:48.453700Z

Ah, :0โ€ฆ canโ€™t remember why I thought :1. Anyways, glad you have that bit working. google-chrome next, eh?

FHE 2021-05-03T01:40:02.453900Z

Well...it's not working.

FHE 2021-05-03T01:40:31.454100Z

Or...you're saying the Ubuntu really didn't ship with a single browser on it?

FHE 2021-05-03T01:40:41.454300Z

...and just installing one will resolve this?

FHE 2021-05-03T01:54:04.454600Z

@seancorfield Will I installed Chrome, and YIKES. Tons of errors when trying to run it (`google-chrome`):

FHE 2021-05-03T01:55:49.454800Z

libGL error: No matching fbConfigs or visuals found libGL error: failed to load driver: swrast ...and many more errors, like 'Failed to connect to the bus [...], and 'Exiting GPU process due to errors [...]', and 'Passthrough is not supported'. Sigh.

FHE 2021-05-03T01:58:20.455100Z

I did talk to a few people in an Ubuntu chatroom, and they advised against running a Linux browser for this purpose, and said it should be possible to instead get the WSL2-Ubuntu-based program to talk to a Windows browser. (Their main argument was speed, which I don't care much about at this point, but if it would just work...) None of them were ClojureScript devs, though. What do you think?

FHE 2021-05-03T02:02:23.455500Z

O...M...G... Even with all those errors, the browser actually did run (under VcXsrv). I was just not noticing a tiny Chrome pop-up that demanded I decide whether to make Chrome my default browser and whether to send crash and usage reports to Google before, you know, actually launching the browser.

FHE 2021-05-03T02:04:26.455700Z

It completely freezes the CLI, though. And if I [Ctrl]+[c] to get the CLI back, the browser window disappears.

FHE 2021-05-03T02:29:06.455900Z

I just opened a 2nd Ubuntu CLI. Good enough I guess?

FHE 2021-05-03T02:35:32.459100Z

Sorry for the wall of text, but I just want to explain what just happened when I finally got my ClojureScript Quick Start guide program working under WSL2. --- tl;dr The question is: Should I develop CLJS using a Linux-side brower in a VcXsrv X11 window, or in a Windows browser? ---

FHE 2021-05-03T02:37:08.460100Z

A crazy (to me at least) thing happened while trying to get my CLJS Quick Start Guide hello world program working on WSL2. When I finally ran my tiny hello-world test program and pointed the Linux browser at localhost:9000, it showed what it was supposed to show (Yay!)....but then this, Windows browser (the one I talking to you in) got hijacked and automatically opened a new tab to localhost:9000 (also with the correct output)!!

FHE 2021-05-03T02:38:25.461300Z

When I put a JS alert in the REPL, the alert only pops up in the Linux browser, not the Windows one. Still, though. Utterly surprised it reached out and touched the Windows browser at all. I thought WSL2 (specifically, not the case in WSL1 AFAIK) OS instances were built as if on a separate network/IP. I did not expect localhost:9000 alone to work for the Windows browser side. I was actively deciding to not bother trying to get that working since I had been given advice to just do it all on the WSL2-Linux side. Stranger still is what happened later... The Windows browser I mentioned above is Firefox. The Linux one is Chrome. I just brought a Windows Chrome browser into the mix, and tried pointing that one at localhost:9000 and it works perfectly, displaying the correct page (like the Windows Firefox) but also responding with the JS alerts I put through (unlike the Windows Firefox, but like the Linux Chrome). ...but only one of the Chrome browsers will generate the JS alert, and after some testing it just appears to be whichever browser I more recently hit [F5] (refresh) on!

FHE 2021-05-03T02:42:13.463700Z

So...I wasn't trying to get a Windows browser to work for this, and expected that would take some network-fu and was going down the road to getting a Linux browser to work, but...is there any reason I should use the Windows browser instead since it was kind of just dropped into my lap as a possible alternative?

seancorfield 2021-05-03T02:48:06.463800Z

Right. When you start up cljs, google-chrome should launch from WSL2 automatically.

seancorfield 2021-05-03T02:48:53.464Z

And yes, if you start a program from the command-line, itโ€™s going to โ€œfreeze the CLIโ€ unless you add &amp; at the end of the command to run it in the background.

seancorfield 2021-05-03T02:51:39.464800Z

I have to say that I have not seen any Windows browser respond to ClojureScript running inside WSL2.

FHE 2021-05-03T02:52:03.465100Z

Right? I was floored.

FHE 2021-05-03T02:54:38.465200Z

OK, thanks! I think I'll just let it freeze that CLI and open a new one. I guess I'd like to keep things as visible as possible. I still can't believe all those errors are normal/fine/ignorable, but I guess I'll move on to my next challenge.

FHE 2021-05-03T02:58:33.468Z

Similar question: Windows Emacs or WSL2 Linux (Ubuntu) Emacs? (either one acting upon program source code files in the WSL2) I went through the process of setting up Doom Emacs on the WSL2 Ubuntu 20.04, but I just realized I could probably simply use my existing Windows Doom Emacs installation to act on the files in the WSL2 file system (in \\wsl$\Ubuntu-20.04 ).

hindol 2021-05-03T09:51:13.478800Z

For me, Emacs in WSL2 works much better. If you are facing some issues with the setup, maybe I can help.

hindol 2021-05-03T09:51:31.479100Z

I highly recommend Emacs on WSL2 than Emacs on Windows.

hindol 2021-05-03T09:53:26.479300Z

The Windows Emacs will be slower on WSL2 files and similarly Emacs on WSL2 will be slower when editing files on the Windows filesystem. So, stick to editing files that are local to that Emacs.

FHE 2021-05-03T02:59:03.468600Z

I did not expect to have options for either thing (input (source code editing) or output (browser))!

FHE 2021-05-03T03:24:42.469200Z

So I guess now that I have a browser working, I should move on to installing figwheel-main on the WSL2 Ubuntu 20.04?

FHE 2021-05-03T03:35:20.471500Z

Or...according to the CLJS Quick Start Guide I might need Node.js? I can't remember if, when I did my tiny webapp under Windows ages ago, I did anything with Node. How important is it? Can I just skip it and move on with installing Figwheel-Main, figuring out CIDER, and figuring out more about deps.edn (and maybe tools.deps IIRC)?

seancorfield 2021-05-03T05:23:49.473300Z

I skipped node and used Figwheel. I think if you use Shadow-cljs you kind of have to embrace node and its package manager (you can use Shadow without node, so I'm told, but it's not "normal"). I can't offer an opinion on Emacs/CIDER because I haven't used it for years.

Chandru 2021-05-03T07:35:24.475500Z

Hi all. What is a good way to go about building mobile apps using Clojure (or Clojurescript)? Most of the examples focus on Cljs + ReactNative but I also see that re-natal hasnโ€™t been updated in quite sometime (and is supposedly fallen behind ReactNative APIs?).

danieroux 2021-05-03T07:37:28.475600Z

"GitHub - vouch-opensource/krell: Simple ClojureScript React Native Tooling" https://github.com/vouch-opensource/krell

Chandru 2021-05-03T08:07:17.475900Z

Thanks. Will look into this!

Audrius 2021-05-03T09:35:32.478400Z

What would be the best way to parse this string -XX:+UseG1GC to 2 tokens: xx and +UseG1GC ? first token between - and : and second is what is left after : . I think there might be a function that does exactly that.

2021-05-03T09:49:36.478500Z

regex or some parser combinator library, https://github.com/blancas/kern for example

1โœ”๏ธ1โž•
hindol 2021-05-03T09:51:13.478800Z

For me, Emacs in WSL2 works much better. If you are facing some issues with the setup, maybe I can help.

hindol 2021-05-03T09:51:31.479100Z

I highly recommend Emacs on WSL2 than Emacs on Windows.

hindol 2021-05-03T09:53:26.479300Z

The Windows Emacs will be slower on WSL2 files and similarly Emacs on WSL2 will be slower when editing files on the Windows filesystem. So, stick to editing files that are local to that Emacs.

pavlosmelissinos 2021-05-03T09:56:48.479600Z

If - is always going to be the first character, clojure.string/split might also be more than enough (for a quick and dirty solution):

(clojure.string/split (subs "-XX:+UseG1GC" 1) #":")

=&gt; ["XX" "+UseG1GC"]
(clojure.string/split (subs "-XX:+UseG1GC:lala" 1) #":")

=&gt; ["XX" "+UseG1GC" "lala"]
you can even set a limit
(clojure.string/split (subs "-XX:+UseG1GC:alala" 1) #":" 2)

=&gt; ["XX" "+UseG1GC:alala"] 

1โœ”๏ธ
jumar 2021-05-03T10:22:27.480100Z

Just curious: why are you doing that? ๐Ÿ™‚

Audrius 2021-05-03T10:24:02.480300Z

I just need to show these parameters in UI. As we can restart the whole app with different JVM start up parameters if needed

2021-05-03T14:56:03.480600Z

@factorhengineering I would imagine this is extremely frustrating, all of emacs, windows dev, browser dev, and cljs are fiddly setups with a lot of weird evolved baggage and a lot of special case tweaks. If this gets overwhelming I'd advocate taking on fewer weird new things at a time, eg. starting with jvm clojure on osx (or linux if you are comfortable with it) and just using whatever editor you know best already

Endre Bakken Stovner 2021-05-03T16:00:57.481800Z

Is there a way to have Clojure automatically run the latest version of my code? So that whenever I save a file, the code in that file updates whatever is running?

2021-05-03T16:06:58.482600Z

there are tools that help with that, eg. tools.namespace/refresh or the ring refresh wrap-reload plugin, but nothing universally adopted

sova-soars-the-sora 2021-05-03T16:07:24.483300Z

if you're talking about a web server there is also the wrap-reload middleware

2021-05-03T16:07:31.483500Z

there are certain constructs like defmulti and defprotocol that break in weird ways if you just blindly reload on file write

2021-05-03T16:07:50.483700Z

thanks - I was thinking of that but forgot the name

2021-05-03T16:07:59.483900Z

that's the "ring refresh" I was thinking of

sova-soars-the-sora 2021-05-03T16:08:42.484900Z

that's true, certain things get a little kinky with reloading, like if you change a route definition or add a route, i find that sometimes i need to restart the server... but usually it works great if there is no clash

sova-soars-the-sora 2021-05-03T16:09:13.486100Z

in clojurescript land shadow-cljs and figwheel will both "hot-reload" code ... a very useful feature for cljs development

2021-05-03T16:09:13.486200Z

right - and for any given construct there's a right way to reload that doesn't break things, but just reloading every file in the order saved is never it

Endre Bakken Stovner 2021-05-03T16:09:38.486900Z

Will have to look into those, thanks!

2021-05-03T16:10:38.488Z

there are also more heavy handed things in the design domain, like stuartsierra/component or weavejester/integrant which are designed to make apps that always reload correclty (though usually they require you to explicitly reload and don't rely on file change on disk)

2021-05-03T16:11:14.488800Z

these definitely have advantages beyond reloadability (like making testing easier, and making it easier to impose a larger scale design of a program)

Endre Bakken Stovner 2021-05-03T16:13:58.489900Z

Yes, I really like the look of integrant, but haven't tried it yet. Mount is the one used in luminus so I just went with it :)

2021-05-03T16:16:17.491Z

OK, well mount also has facilities for reload - if you set up your tool to run (mount/stop), then reload your namespaces, then (mount/start), that should take care of everything (as long as you use mount correctly)

1๐Ÿ™
2021-05-03T16:16:53.491700Z

I don't like mount because instead of resolving things like dependency cycles via data, it cuts the gordian knot and uses globals

1โž•
2021-05-03T16:17:38.492Z

more detail about reloading with mount here: https://github.com/tolitius/mount#the-importance-of-being-reloadable

2021-05-03T16:18:01.492500Z

using tools.namespace which I mentioned above

dpsutton 2021-05-03T16:23:43.494200Z

and depending on where you are in your journey, asking for things like this could mean that you are missing the benefits of repl driven development. Clojure is kinda designed to have things always up-to-date with a primitive of eval. Re-evaling forms will "update" a live system as you go. Getting used to how the repl works can often make this desire for reload-on-save go away

Endre Bakken Stovner 2021-05-03T16:24:58.495Z

But surely just saving is even less work than sending stuff to the REPL? But you are correct, I am not good with REPL-driven development.

dpsutton 2021-05-03T16:27:31.496600Z

kinda. the way many of these things work is that on save, they will look for other namespaces that depend on the saved namespace and refresh all of them by sending all the forms to the repl. So in one sense saving a file is less work, but you want to trigger a lot of work based on saving the file.

2021-05-03T16:28:50.498Z

the act of saving is less work, the things you need to do to verify the state of the code or experiment with the data in context is significantly harder outside a repl based flow - to the degree that many devs don't even end up doing it or replace it with nearly acceptable alternatives like tests or printlns

2021-05-03T16:29:30.498700Z

it's just that once you are using the repl to best advantage, the whole reloading files thing becomes much less important

Endre Bakken Stovner 2021-05-03T16:30:35.499900Z

I will have to learn it then ๐Ÿ™‚ Wish I still had my purelyfunctional subscription, they had a course on REPL-driven development :thumbsup:

2021-05-03T16:30:53.000300Z

(and this isn't to say that repl replaces testing, just that people will use tests for the kind of exploritory thing you can do in a repl - which is possible but much more work)

dpsutton 2021-05-03T16:31:02.000500Z

this is pretty great: https://clojure.org/guides/repl/introduction

2021-05-03T16:31:37.001200Z

actually my one beef with repl driven dev is that it can lead to workflows where people are tempted to skip writing good tests (because hey I verified it worked in the repl right?)

1โ˜๏ธ
dpsutton 2021-05-03T16:31:55.001800Z

you took a good stab at that didn't you?

dpsutton 2021-05-03T16:32:03.002200Z

creating tests from a repl session?

2021-05-03T16:32:04.002300Z

which isn't a problem with rdd itself, just a growing pain of adopting the repl

2021-05-03T16:32:37.002900Z

@dpsutton I had some ideas but nothing I'd suggest for mainstream use (maybe with more thought and design, eventually...)

2021-05-03T16:33:17.003500Z

I did make a tool that dumps data from an app or repl in a way that can easily be re-inflated from a test, yeah https://github.com/noisesmith/poirot

NoahTheDuke 2021-05-03T17:26:41.004Z

this is my major problem with common lisp (and the CL eco-system). the existing test libraries aren't great and most libraries don't include more than perfunctory tests because of the heavy reliance on developing in the repl

2021-05-03T17:29:07.004200Z

yeah, it could be framed as a moral hazard, to borrow a concept from economics

2021-05-03T17:30:02.004400Z

(I do have beef with how moral hazard is applied to policy - funny how moral hazards that benefit the poor are never acceptable, and ones that benefit the rich are never articulated...)

Ory Band 2021-05-03T17:33:39.005200Z

hi. i need to send some http requests. which http client do you recommend? clj-http, http-kit, aleph, other?

NoahTheDuke 2021-05-03T17:35:36.005800Z

i've been really happy with http-kit.

Ory Band 2021-05-03T17:39:41.006200Z

have you tried any alternative? any specific reason? or was it just the first option you tried that worked fine

Ory Band 2021-05-03T17:40:05.006500Z

thanks also

Ory Band 2021-05-03T17:42:45.006800Z

i forgot to mention i'm mostly interested in making async http calls

NoahTheDuke 2021-05-03T18:00:36.007900Z

it's the one in use when i joined my current project and have stuck with it when doing other things since

1๐Ÿ™
FHE 2021-05-03T18:46:36.008100Z

@danie The write-up on the git page for krell says shadow-cljs can be used for react native, but I don't see anything to that effect on the git page for (or other things I've read about) shadow-cljs. Do you happen to know how much shadow-cljs actually helps with mobile? (I realize you're not recommending it, though. Ha ha.)

GGfpc 2021-05-03T19:15:24.008600Z

Is there any way I can see the request body sent by http kit?

GGfpc 2021-05-04T18:55:59.130Z

both options worked perfect, thanks ๐Ÿ™‚

phronmophobic 2021-05-03T20:01:05.008900Z

see http://http-kit.github.io/client.html#coercion

phronmophobic 2021-05-03T20:02:27.010300Z

thereโ€™s a number of different ways to work with the request body. :as text is probably the most straightforward, but it depends on your use case

GGfpc 2021-05-03T20:16:00.010500Z

Sorry, I'm not sure if I made it clear. I want to see the body that I'm sending

GGfpc 2021-05-03T20:16:07.010700Z

to make sure it's formatted correctly

phronmophobic 2021-05-03T20:20:29.011100Z

the way I would do that is with netcat, nc In terminal

nc -l 1234 &gt; request.body
Then send a request to "http://localhost:1234/myreq"

phronmophobic 2021-05-03T20:21:22.011300Z

that will write the request body to the file named request.body

borkdude 2021-05-03T20:56:15.012500Z

FWIW babashka also comes with httpkit, both client and server. It's a quick way to test it out if you're interested in trying the lib.

1๐Ÿ‘Œ
borkdude 2021-05-03T20:59:53.013200Z

A quick way to see both the request body and response is to launch the server and fire a request at it with the client:

$ bb -e '(org.httpkit.server/run-server (fn [r] (clojure.pprint/pprint r))) @(org.httpkit.client/get "<http://localhost:8090>")'
\cc @ggfpc12495

sova-soars-the-sora 2021-05-03T21:04:34.013900Z

Super groovy cartoon movie

Grzegorz Smajdor 2021-05-03T21:05:37.014300Z

How one uses https://cljdoc.org/d/clojure-interop/cljs-web-api/1.0.0/api/speech.SpeechSynthesis#speaking this in cljs?

Grzegorz Smajdor 2021-05-03T21:07:41.014500Z

I did this https://gist.github.com/gs/724901095173add6284e1c0ab712b9ae but probably there is a better cljs way

Grzegorz Smajdor 2021-05-03T21:08:45.014800Z

Iโ€™ve put this on heroku to test https://frozen-oasis-40568.herokuapp.com/

2021-05-03T21:55:55.015700Z

Is there anything like dynamic-wind in clojure(script)? (Where code will run, even if the scope is left via an exception.)

2021-05-03T21:56:20.016300Z

Alternatively, is there anything like reset! , but only inside of a lexical scope?

2021-05-03T21:56:41.016400Z

Something besides try / catch you mean?

2021-05-03T21:57:55.016600Z

Yes, because I don't want to intercept any exceptions, just reset an atom on the way out.

2021-05-03T21:58:03.016800Z

I think dynamic wind is more like try / finally(?)

2021-05-03T21:58:31.017Z

it's not about catching, but rather ensuring your finally block always runs, regardless of code path / errors, right?

2021-05-03T21:58:35.017200Z

Close, it's more like try/catch(e)->rethrow-e/finally

2021-05-03T21:59:14.017400Z

I think noisesmith might be right that try with no catch, only a finally, will propagate the exception, but still run your finally code on the way out.

2021-05-03T21:59:27.017600Z

cljs.user=&gt; (try (throw (js/Error.)) (finally (print "OK")))
OK
Execution error (Error) at (&lt;cljs repl&gt;:1).
looks like a start at least

2021-05-03T21:59:31.017800Z

unless a try/finally block doesn't intercept exceptions?

2021-05-03T21:59:55.018Z

throw followed by finally seems odd

2021-05-03T21:59:55.018200Z

a throw is saying your code block is done for good

2021-05-03T21:59:59.018400Z

Oh yes, you're right, that works.

2021-05-03T22:00:13.018600Z

Thanks

2021-05-03T22:00:28.018800Z

right, without catch the exception does what it would have otherwise, it's just that your finally clause runs too

2021-05-03T22:01:01.019Z

Cool, thanks. ๐Ÿ™‚

2021-05-03T22:01:14.019200Z

try/finally is how locking ensures correctness in clj for example (no need for this in cljs with no threading)

borkdude 2021-05-03T22:02:11.019500Z

also thread bindings are managed this way to ensure they are unwinded after the binding expression, there are more examples of this, probably with-open too

2021-05-03T22:04:25.019700Z

Makes sense, thanks. ๐Ÿ™‚

Adrian Aleixandre 2021-05-03T23:47:12.022200Z

Hey does anyone have experience with https://github.com/binaryage/chromex? I am having trouble extending the js/clojure marshalling system and could use some help! How do I go about extending the gen-marshalling config?