Fork me on GitHub
#beginners
<
2021-05-01
>
pinkfrog01:05:38

Would like to the naming convention for this

mobile.ui.components.nativebase :as (nativebase? or cnb? or unb?)
Basically, will you prefix the last part nativebase with some strings?

FHE02:05:51

Hi everyone. It's been a few months since I was here, or attacked trying to piece together my dev environment. The last thing I accomplished with getting WSL2 set up, then Ubuntu, then Clojure CLI tools (including bash, curl, rlwrap, and Java). I'm kind of lost as to what to do next. I can't even see any file system from within this WSL2 thing ('ls').

FHE02:05:39

I just want to be able to create ClojureScript things that can be exported and run on a local browser or from a website. I imagine that will mean creating a shell of a .html webpage including a big canvas area for the ClojureScript program to target, then creating a CLJS project and going from there?

piyer03:05:42

I am not sure what are you trying to achieve. Setup a website?

FHE04:05:47

Yes, basically. Really just want to get started making programs in general, but targetting the browser seems to be the way to go to make my programs easy to let others try.

FHE04:05:06

I followed the ClojureScript quick guide way back, and put together a simple .html webpage then had ClojureScript grab text from an input field, do some useful manipulation of it, and show the resulting text in another area of the webpage.

FHE04:05:15

I just copied and pasted the folder structure from the example, though, and now I'd like to do the project folder and file structure a little better (maybe with a tool?)...or at least understand it better...trying to get that side of things more set and then I want to get into doing more advanced stuff (like actual graphics and real-time interaction---for educational games at first) in the browser.

raspasov04:05:27

@UH5SE3NM9 do you have a ClojureScript REPL/editor all setup?

FHE04:05:46

I have Doom Emacs. Not overly familiar with it, but again I'm trying to up my game.

FHE04:05:23

Last time I used NotePad++, but I understand Doom Emacs has nice parenthesis handling, as well as some kind of built-in REPL that could help?

FHE04:05:44

By the way, when I did my small program in ClojureScript last time, I followed the Quick Guide from the Windows perspective. This approach of doing things from Linux (well, WSL2) is new to me.

raspasov05:05:42

Sorry, I can’t really help with Windows specifically… Last time I used Windows it was in 2009 or so 🙂

raspasov05:05:28

Using MacOS, but can help with Linux basics as well.

raspasov05:05:38

If you have a REPL going, are you using either figwheel-main or shadow-cljs? Those are the two most common options for ClojureScript REPLs and auto-reloading.

FHE05:05:25

Well I'm trying to use WSL2, so I would imagine (hopefully, after the immense amount of time it took to install it LOL) that I shouldn't have to deal with any more Windows-isms.

FHE05:05:20

I mean I'll be running my Emacs in Windows, but operating on files in the WSL2 (Ubuntu) subsystem.

FHE05:05:03

I thought I was told I could just use deps.edn (or maybe that was tools.deps) and not need to used Leiningen or shadow.cljs

FHE05:05:46

Wait a sec...misread what you said. You're talking about the live-update functionality, not the project management piece, right? I think figwheel/figwheel-main or the live-update part of shadow.cljs is in the picture for me, yes (though the project management part of shadow.cljs, like Leiningen, seems to not be needed given what @U04V70XH6 advised me months back (but only a small step ago since I was derailed. Does that sound about right, @U050KSS8M?

seancorfield05:05:32

@UH5SE3NM9 What I was suggesting was doing all your Clojure/Script development on WSL2 so you could avoid "Windows-isms" but I don't know how you will use Emacs on Windows to talk to a Clojure setup on WSL2. VS Code has a "Remote-WSL2" extension that means you can use VS Code on Windows and have your entire dev setup on WSL2.

seancorfield05:05:48

I suspect with Emacs, you'll need to run it on WSL2.

seancorfield05:05:01

And, yes, figwheel-main should give you the live-update experience, and yes you can run figwheel-main using just the Clojure CLI / deps.edn -- see the figwheel-main docs.

FHE05:05:26

Hmm...yes, I guess I'm not just changing files. Emacs and the program are going to be interconnected more than that. Ooof. I hope getting it set up all over again in Linux will not be difficult.

seancorfield05:05:51

Do you like Emacs? What other editors are you familiar with?

FHE05:05:12

I didn't realize I was signing up for moving everything over to WSL2. There isn't even a GUI in it, and I only just figured out how to even see the file system.

seancorfield05:05:48

Clojure sort of expects you to do everything from a terminal 🙂

FHE05:05:24

I've used NotePad++, but I'm getting familiar with Emacs again after using it just a bit a long while ago. It's supposed to be the best for this, isn't it? I mean I even like just taking notes on this (HUGE) set-up-my-dev-environment project in org-mode.

seancorfield05:05:53

As I said above, if you're comfortable using VS Code on Windows, it has an extension that makes the whole WSL2 thing seamless.

seancorfield05:05:16

I haven't used Emacs for five or six years now (but used it on and off for about twenty years prior to that).

FHE05:05:37

Clojure does, OK, but installing other things (Doom Emacs) from terminal? Did not think I was headed in that direction. It's fine though, if it's required. I want the best set-up.

seancorfield05:05:59

Pretty much everything in the Clojure world assumes you're either on macOS or Linux. If you're using Windows, it's painful.

FHE05:05:06

...and I was just starting to get comfortable with Doom Emacs, and hoping I could finally, you know, write some code. Ha 😭

FHE05:05:36

I thought at least my text editor and my browser could still be in Windows. Guess not?

FHE05:05:02

If I had known that, I might have just set up dual-boot instead of WSL2.

seancorfield05:05:38

You can use VS Code on Windows and have your whole dev env running on WSL2 ¯\(ツ)

FHE05:05:45

What is the advantage of WSL2, then? Just being able to alt-tab to Windows stuff completely unrelated to the task of programming?

seancorfield05:05:17

WSL2 means you can do all your development on Linux while keeping your familiar Windows UI and apps.

FHE05:05:54

If VSCode can do it, why can't Emacs? Isn't it all-singing, all-dancing when people want it to be, and wasn't it the first best for doing Clojure dev?

seancorfield05:05:16

Because the VS Code bridge to WSL2 is modern and Emacs is not modern?

FHE05:05:40

Well anyway, I guess I've done all the set-up except installing Doom Emacs. I should find out how difficult it is.

seancorfield05:05:50

Your choice 🙂

FHE05:05:12

I really wish the Ubuntu in WSL2 was the standard GUI kind. Why would be a stripped-down CLI-only thing??

FHE05:05:32

Does it have to be?

seancorfield05:05:49

Linux (and Unix before it) were all originally non-GUI. GUIs are way over-rated.

FHE05:05:49

I'm find with CLI for a few CLI commands, like just running a program, but I would rather run that from within a GUI window with a CLI in it, in a GUI OS.

seancorfield05:05:05

I'm on recent Windows Insiders builds now and have the updated WSL2 that supports X11 GUI apps out of the box. You could always install VcXsrv (Xlaunch) or X410 on Windows to run your X11 GUI apps from WSL2 🙂

FHE05:05:26

Seems like a bait-and-switch to even call the OS in WSL2 (or that 'app') 'Ubuntu' when it's missing a huge chunk of it (all the GUI stuff).

seancorfield05:05:56

It's not really missing anything.

FHE05:05:58

Why would it not just look like the other 3 or 3 times I've used Ubuntu?

seancorfield05:05:16

Windows just didn't support WSL2 GUIs until these recent Insider builds.

FHE05:05:43

A Ubuntu live CD will boot directly into a GUI, from my experience. Why would the WLS2 version be different?

seancorfield05:05:02

They're not even comparable.

FHE05:05:09

strange. They should at least have a modified name for it. ...Ubuntu-CLI

seancorfield05:05:25

WSL2 runs user-mode Linux distros. Not just Ubuntu.

FHE05:05:39

user-mode?

seancorfield05:05:46

I've never run a GUI on Linux. I've never seen the point. And when I got started with Unix flavors, they mostly didn't have GUIs at all.

FHE05:05:51

I don't really mean GUI apps. I just mean the basic GUI OS. You know...like a file explorer, and a start-menu-type thing?

seancorfield05:05:11

That's a window manager/shell. It's just an app.

seancorfield05:05:22

The "OS" doesn't have a GUI.

FHE05:05:49

Oh wait...I see an actual desktop there. Would not have called that an 'app'.

seancorfield05:05:32

That article shows the Windows desktop, running several Linux GUI apps. Not a Linux window manager/desktop.

FHE05:05:41

To me, 'apps' are things you can launch from a CLI or by picking something from a start menu or double-clicking an executable in a file manager.

FHE05:05:08

I would never have considered the actual menu or file explorer 'apps', but I guess one could.

FHE05:05:41

Sounds like they're almost there. Ha.

seancorfield06:05:15

The latest builds have full sound and video integration between Linux and Windows. It's pretty impressive.

seancorfield06:05:59

I have Google Chrome (Linux) installed and it behaves just like a Windows app in terms of launching it from Windows -- or from Linux.

seancorfield06:05:29

I run Reveal from my Clojure REPL and it pops up as a (Linux) GUI.

FHE06:05:00

I set up the cljs quickstart thing. Is there a browser I can launch in WSL2 (while stuck on the clojure CLI!) to see my process? A browser on Windows can't see it, it seems like.

seancorfield06:05:09

But I like having VS Code as a native Windows experience, but having all my files, REPLs etc running on WSL2 -- because I can avoid the problems with Windows command-line.

seancorfield06:05:37

That article explains how to install Google Chrome or Microsoft Edge on WSL2.

FHE06:05:38

...though I would have guessed maybe something like localhost:9000 in WSL2 might be visible in Windows too.

seancorfield06:05:59

(but you'll need to be on recent Insider builds)

FHE06:05:35

OK. Something else to attack tomorrow, after trying to install Doom Emacs. Ugh...I took so long to get that set up. Like...days. I took lots of notes though. Here's hoping. 😕

seancorfield06:05:35

Or, as I said earlier, install X410 or VcXsrv/Xlaunch and you can run X11 apps on WSL2 and the GUI will appear "on Windows".

FHE06:05:34

Wait a minute...so you're saying with a WSL2 installation from just a few months ago there is NO WAY to get it live-updating a browser?

seancorfield06:05:37

ClojureScript starts Google Chrome (on WSL2) for me -- either via the quick start or figwheel or shadow-cljs

seancorfield06:05:53

No, I'm not saying that.

FHE06:05:01

I mean assuming I'm using Emacs and not that specific VSCode functionality.

FHE06:05:18

The quickstart isn't doing it.

seancorfield06:05:22

I have no idea how to get Emacs-on-Windows to talk to the WSL2 filesystem.

FHE06:05:33

I just ran

FHE06:05:34

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

seancorfield06:05:48

Of course it isn't: you don't have an X Windows server running on Windows to support GUI apps on WSL2 do you?

seancorfield06:05:31

Months ago -- long before this latest Wayland stuff -- I was using VcXsrv on Windows to support WSL2 GUI apps and had Google Chrome installed (on WSL2), and the live-update-in-the-browser thing works fine with that.

FHE06:05:37

I'm not worried about the editor just yet.

FHE06:05:53

I've set up the quick start stuff just using vim on WSL2

FHE06:05:22

So I also tried this (since no browser auto-opened), but how can I launch one?

FHE06:05:25

If you are running Linux and the REPL does not start, try disabling browser auto-launch and opening manually:

clj --main cljs.main --repl-opts "{:launch-browser false}" --compile hello-world.core --repl

seancorfield06:05:50

Because from the Windows side, WSL2 is not "localhost", it has it own IP address.

FHE06:05:55

How can a person launch anything when the CLI has been taken over by a REPL anyway??

seancorfield06:05:16

Run multiple terminal windows?

FHE06:05:21

That makes sense. But what about a WSL2 browser?

FHE06:05:33

Seems like one was supposed to auto-launch with the first command.

seancorfield06:05:34

Microsoft's new Terminal has tabs which is what I use.

seancorfield06:05:45

Do you have an X11 server installed on Windows?

FHE06:05:24

I did install that, but it is only offering me PowerShell, Command Prompt, or some Azure thing....no WSL2 as promised.

seancorfield06:05:34

As I said above: months ago I was running Google Chrome on WSL2 with VcXsrv on Windows and the quick start worked fine, starting Google Chrome on WSL2.

FHE06:05:40

Install Terminal, I mean.

FHE06:05:49

No idea about an X11 server.

FHE06:05:11

VcXsrv...ok

seancorfield06:05:25

When I installed it, Ubuntu (WSL2) was available in Terminal. I edited the Terminal config to make it the default.

FHE06:05:26

I just found this. I might try it tomorrow:

seancorfield06:05:59

Here's my new tab menu in Microsoft Terminal:

FHE06:05:24

But OMG the goalposts just keep moving on me. It's demoralizing. New, unexpected tasks: (1) Figure out how to get a second WSL2 CLI (when Terminal isn't offering it). (2) Figure out how to get a browser running in WSL2. (3) Figure out what X11 is an how to get that going. (4) Figure out how to get Doom Emacs installed on WSL2.

seancorfield06:05:22

Life as a software developer. Always new hills to climb.

FHE06:05:23

I could almost swear I had that same top menu item (Ubuntu) in my Terminal right after I installed it....but it's not there now.

seancorfield06:05:10

Pretty much every week I find new stuff I have to learn how to do -- and I've been at this professionally for 40 years 🙂

FHE06:05:54

I wouldn't mind new hills to climb to do more advanced stuff, but at this point I'm weeks and weeks in and still just trying to get a single line of code to take shape in a browser.

FHE06:05:16

I don't doubt that this way will eventually be 'better' than the Windows-centric way I did my first little webpage program, but it is so far 20x the work to set up.

seancorfield06:05:53

Clojure isn't easy to work with. None of its tooling is designed to be easy. And Windows just makes things harder.

FHE06:05:34

If all of those things on my to-do list don't come easily, I might just give up on WSL2 and just set up dual boot with standard Ubuntu.

FHE06:05:04

I'm not seeing any point of sticking with Windows now

seancorfield06:05:17

If you're comfortable using Ubuntu "natively" that might well be easier. Last time around you seemed pretty resistant to using Linux at all and you seemed determined to stay on Windows.

seancorfield06:05:05

If you're happy to move off Windows for Clojure development, it would all be easier. Both Linux (native) and macOS are much more common in the Clojure world and so it's much easier to get everything to work on those platforms.

seancorfield06:05:28

I would never have considered Windows as a development platform if it wasn't for WSL.

FHE06:05:45

I wouldn't say I was ever determined to stay on Windows. I just had made a program from within Windows and really just wanted to get into something with some good project management features and live browser updating. I did not expect it to take such a change to get that.

FHE06:05:50

...or does it have to?

seancorfield06:05:01

But I want a non-Linux desktop OS because the UX is just so much better than Linux's weird window managers etc.

FHE06:05:38

I thought it would be as simple as shadow.cljs (or Leiningen and figwheel-main) and Emacs+CIDER and good to go.

seancorfield06:05:16

When I use Linux, I use the terminal only. It's what I originally liked about OS X: nice, modern GUI OS with modern apps but a full *nix terminal under the hood. And that was how I had my Macs setup back in the System 6 / System 7 days too.

seancorfield06:05:07

On macOS or Linux, yes, it would be that simple / good to go. But very few Clojure tools are designed to work on Windows because very few Clojure developers use Windows.

FHE06:05:24

Some people just use those from within Windows without WSL2, don't they? Or are there really zero people who have ever made a program more advanced than mine from within Windows without WSL2?

FHE06:05:56

I think you just answered my question while I typed it.

seancorfield06:05:22

From the 2021 State of Clojure survey results:

FHE06:05:31

Kind of unbelievable that Windows has the market share it has and comes preinstalled on so many computers but is not supported well for programming. The situation is an unfortunate barrier to entry to programming.

seancorfield06:05:47

Windows was designed for consumers, not programmers.

FHE06:05:52

Hey 4.77%. I wonder what they do?

seancorfield06:05:11

Microsoft are doing great work these days making Windows viable for programmers.

raspasov06:05:16

Well, I assume it’s decently supported for C# stuff? (I have never used C# professionally, that’s just an assumption)

seancorfield06:05:40

Sure, with fancy button-clicking UI-based IDEs.

FHE06:05:56

I'm not married to Windows. I've had (secondary) computers running only Ubuntu before (GUI though). My opinion regardless.

FHE06:05:39

Yeah maybe it's just my dumb luck I came down to a programming language that is extra hostile to Windows.

raspasov06:05:31

If I were you, I’d use Ubuntu (I have used it in the past); I bet most things there with JVM + Clojure should “just work”

FHE06:05:59

I've been meaning to dual boot for ages anyway. But before I go to that. Does this sound like the full list of doable things I have left to get going with WSL2? (1) Figure out how to get a second WSL2 CLI (when Terminal isn't offering it). (2) Figure out how to get a browser running in WSL2. (3) Figure out what X11 is an how to get that going. (4) Figure out how to get Doom Emacs installed on WSL2.

raspasov06:05:19

Also, I’m biased, but if you also use IntelliJ + Cursive, then things will also “just work”; Been using Cursive since ~2014 and I am a very happy user.

FHE06:05:29

Well I'm going for ClojureScript, not Clojure. Does that matter?

raspasov06:05:42

I’ve seen the “problems” most other people run with in other editors and I just shake my head 🙂

raspasov06:05:47

Yes, that’s supported also.

FHE06:05:17

And you're running that on just a GLinux machine?

seancorfield06:05:21

I can't speak to Cursive -- I don't like IntelliJ at all (and I've tried a lot of different releases of it). Editors are very subjective.

FHE06:05:00

Ah. Same thing when it comes to all these programming tools, though, yes? *nix?

raspasov06:05:01

@U04V70XH6 What specifically do you not like about it? (I realize, it needs a fast computer with a lot of RAM)

seancorfield06:05:08

Yeah, macOS is far and away the easiest setup for Clojure and ClojureScript. Pure Linux is probably second easiest. Windows is just hard.

seancorfield06:05:42

@U050KSS8M I'm not much of a fan of IDEs at all and I just find IntelliJ to be slow and bloated and weirdly organized.

FHE06:05:58

That's sad if true. Most difficult OS to get is the easiest to use for this?

seancorfield06:05:17

I've never liked its UI. I preferred Eclipse over IntelliJ (and I don't like Eclipse much either).

seancorfield06:05:31

macOS is easy to get. It's just expensive 🙂

FHE06:05:43

Should I just try to run MacOS instead of Ubuntu on this ThinkPad? LOL

raspasov06:05:02

Yea I agree it’s bloated… I don’t use 99% of it’s stuff, but the Cursive stuff just works for me. Also, run very minimal UI for it:

seancorfield06:05:54

Although the recent shift to M1 chips means quite a few things don't work yet I believe. Not the first time Apple's done this. I started on 680x0 chip Macs, went through the RISC chip switch, then went through the Intel chip switch.

raspasov06:05:28

MacOS on ThinkPad…. I can sense that can be another week-long project 🙂

FHE06:05:35

Yeah I'm on a nvm-e drive here, so no go for MacOS?

raspasov06:05:39

(I would say no, unless you’re just keen on tinkering)

FHE06:05:00

'week-long' would be a fantastic relief at this point. 😕

FHE06:05:50

So anyway, how long should I give that to-do list above before throwing in the towel on WSL2 and just dual-booting?

raspasov06:05:43

Yes, I heard M1 had some problems, but anecdotal reports say most things work already; But I have no first hand experience (yet).

FHE06:05:51

Is my list about right? No more surprises? ...at least until after I try to do something more advanced than hello world in a browser through WSL2? lol

raspasov06:05:41

Sorry, I can’t really judge or make a call about Windows/WSL2. Never tried it. But my recommendation about Ubuntu, in general, still stands, given your current hardware.

seancorfield06:05:59

Here's what my Clojure dev looks like on Windows/WSL2 with Reveal:

seancorfield06:05:51

That's VS Code native on Windows, Reveal running as an X11 app and a Socket REPL started from the command-line in Ubuntu.

FHE06:05:09

Reveal? New terms today: x11, vxm..whatever that term was, and reveal.

seancorfield06:05:48

I used Cognitect's REBL before that for visualizing results of evalutions.

FHE06:05:54

WOW...it got late. Will probably have kids waking me up in two hours. Better go. Thanks for the help so far. Will definitely check this space again tomorrow, and update you on my fight.

jholmgren15:05:42

I appreciate the dialog in this thread and can relate to too many of the thoughts discussed. As a student of the language/ecosystem in my precious few moments of spare time, I admit I default to the path of least resistance for working through the problem in front of me. Given what I've read, if you are attempting to get something fired up quickly and are familiar with creating VMs I'd probably just fire up a VM with your favorite distro to accomplish your immediate goal.

FHE15:05:32

I've downloaded VMWare before but that's as far as I ever got. There was some kind of stumbling block and at the time no great reason for me to use a VM other than just for a fairly secure browser. Thanks for the idea, though. I just might do that. Could it be easier/better than WSL2 and easier than setting up than dual booting (and continuing to dual boot)?

jholmgren17:05:17

I'd say whichever you're most comfortable with is the right choice here. Windows does have Hyper-V built in and VirtualBox has treated me well in the past as well, but to each their own. I like the ability to teardown and rebuild VMs at will so, I'd personally take the VM route.

FHE20:05:10

Extremely basic VM question: They can be persistent (or rather save state) across restarts/sleeps/userchanges of the host system, yes?

seancorfield20:05:50

Yes. That's essentially what WSL2 is: a VM.

FHE21:05:44

So between a VMWare VM and WSL2...?

seancorfield21:05:24

@UH5SE3NM9 You should already know my answer 🙂 WSL2 provide full integration with Windows — you can access the Windows filesystem easily within it, you can use Windows apps within WSL2 (e.g., using notepad.exe README.md to open that (Linux) file in (Windows) NotePad, you can also start Linux apps from Windows (in the latest version of WSL2/Windows) — e.g., Google Chrome from Linux appears in my Windows Start Menu. If you use a standalone VM, like VMWare, you won’t have that sort of integration.

seancorfield22:05:58

(and with VS Code, at least, you can have a full Windows-native editor experience while still having everything running on WSL2)

FHE22:05:15

Oooh. Actually I don't think I happened upon the fact that it can access the Windows file system. I did come across the fact that Windows can access the WSL2 file system, though, which is good.

FHE22:05:10

How does one navigate to the Windows file system from the WSL2 Ubuntu CLI?

seancorfield23:05:06

/mnt/c is your C: drive.

FHE00:05:54

Nice and simple. Thanks!

FHE02:05:31

So my task list from last night was: (1) Figure out how to get a second WSL2 CLI (when Terminal isn't offering it). (2) Figure out how to get a browser running in WSL2. (3) Figure out what X11 is an how to get that going. (4) Figure out how to get Doom Emacs installed on WSL2.

FHE02:05:10

(1) was easy: just launch the Ubuntu Windows app a 2nd time for a 2nd CLI

jholmgren03:05:05

Or use Windows Terminal and have them tabbed

FHE03:05:16

(4) I did next. It took hours and hours but it's done now. Doom Emacs (27.2) looking fine on WSL2 Ubuntu 20.04 (CLI-only), though until now I had never seen it not it its own window.

FHE03:05:41

Windows Terminal will not offer me that option. Only command prompt, powershell, and some azure thing.

FHE03:05:18

I thought it offered the WSL2 option after I first installed it a while back, but if it ever did it has since disappeared.

jholmgren03:05:28

It definitely should list all distros installed. In the dropdown and you should be able to configure your default.

FHE03:05:36

I think (2) will follow from (3). I am trying to understand it now. Based on this info I think I just need a single window-launcher thing. https://utf9k.net/blog/emacs-wsl2-install/#an-optional-prerequisite

FHE03:05:26

@U04V70XH6 had recommended VcXsrv, but I thought I heard bad things about SourceForge a while back, and X410 is available as a Win10 app. Hmm...

jholmgren03:05:32

@UH5SE3NM9 It seems you're not alone with the disappearing WSL profiles in the Windows Terminal. https://github.com/microsoft/terminal/issues/6946

FHE03:05:38

Aha. Glad to know it's not something I messed up.

seancorfield05:05:39

Looks of useful information about workarounds in that issue. Interesting stuff.

seancorfield18:05:50

In a wonderful stroke of irony, I fired up my laptop today, fired up Terminal, and my Ubuntu profile was missing -- just like issue 6946. First time I'd ever encountered that. I rebooted, let my machine settle down -- waited for all the startup processes to complete -- and then started Terminal and Ubuntu was there as usual. So, as the issue suggests, this is a timeout issue that WSL doesn't respond quickly enough if you open Terminal while your system is "busy". Interesting.

noisesmith14:05:03

@UH5SE3NM9 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

Ho0man07:05:48

Hi everyone. I've been trying to use lmax disruptor in a Clojure project, where as I understand publishing to the ring buffer requires deep copying objects to pre-allocated slots on off-heap memory. How can I achieve that with Clojure collections (map, vectors, etc) ? Thanks in advance.

didibus09:05:08

The disruptor I think is meant to be used with mutable objects to save on object allocation

didibus09:05:44

So I don't think you can use it with Clojure immutable data-structures

didibus09:05:04

Though you could create an event that has a Clojure Map as a field on it, but make sure you clear it after use like it says in the user guide

Ho0man09:05:12

@U0K064KQV If I create a class with clojure data structures as its field : • does the pre-allocation work correctly ? • when I set that field with some clojure collection, are they copied onto the off-heap location ? or is it merely their reference that is passed ?

Ho0man09:05:14

@U0K064KQV Also what did you mean by "clearing it after use" ? did you mean to clear the offsets on the ring-buffer ?

didibus09:05:24

The data isn't copied off heap

didibus09:05:56

It's more like an EventPool similar to having a ThreadPool

didibus09:05:51

So if your ring buffer has 1024 slots, it'll pre-allocate 1024 events. That means it'll create all event objects when creating the RingBuffer and store them all in it.

didibus10:05:18

When you publish to the Ring Buffer, you reuse the event objects already in it, so they have to be mutable

didibus10:05:26

If you set a field on them with a Clojure collection, after you consume the event, the event object will continue to point to the Clojure collection and so it won't be garbage collected. So you need to clear it, after you consume the event you have to set the field back to null.

didibus10:05:52

If you want to avoid even the GC pressure of creating Clojure collections, you can choose to put your own data off heap and set on the event the offset into your off heap byte buffer

didibus10:05:30

But you're not dealing with Clojure data-structures at this point, you've got your own custom memory layout and structure.

didibus10:05:57

Or you can use only primitive fields on your Events.

Ho0man11:05:38

Thanks This helped a lot

zackteo10:05:21

Has anyone ever encountered such a problem before when trying to interop with a Java library?

1. Caused by java.lang.IllegalArgumentException
   Mismatched return type: defineConstraints, expected:
   [Lorg.optaplanner.core.api.score.stream.Constraint;, had:
   org.optaplanner.core.api.score.stream.Constraint
There's no such thing as Lorg.optaplanner.core.api.score.stream.Constraint in Optaplanner. So I am not sure where that Lorg came from

didibus10:05:54

[L means it's an array of org.opr...

zackteo10:05:52

hmmm the exact code is

(defn ^ConstraintProvider ->make-provider []
  (reify ConstraintProvider
    (^Constraint defineConstraints [this ^ConstraintFactory cf]
     (object-array [(room-conflict cf)
                    (teacher-conflict cf)
                    (student-group-conflict cf)]))))

didibus10:05:10

So defineConstraints expected an array of Constraints but you gave it a single instance of Constraints instead

zackteo10:05:29

right hmmm

zackteo10:05:01

What should the type hinting be then ? 😮

zackteo10:05:19

Like how do I translate this type Constraint[] ?

didibus10:05:09

Exactly what the message says

didibus10:05:24

^[Lorg....

zackteo10:05:52

You mean

(defn ^ConstraintProvider ->make-provider []
  (reify ConstraintProvider
    (^Lorg.optaplanner.core.api.score.stream.Constraint defineConstraints [this ^ConstraintFactory cf]
     (object-array [(room-conflict cf)
                    (teacher-conflict cf)
                    (student-group-conflict cf)]))))

zackteo10:05:28

That was what I tried previously. Just executed it again and got

1. Caused by java.lang.ClassNotFoundException
   Lorg.optaplanner.core.api.score.stream.Constraint

didibus10:05:09

Hum... ok ya that was a guess of mine haha

didibus10:05:20

I think you might not need a hint

didibus10:05:37

But you need to use the array function that takes a class

didibus10:05:00

into-array I believe

zackteo10:05:08

No worries 🙂 understanding the L part was helpful! May I know how you knew about it? Or just something to remember

didibus10:05:01

https://clojure.org/reference/java_interop See Aliases it briefly mentions it and links to the Java doc for the various letters following [

zackteo10:05:25

the issue is that object-array will end up getting java.lang.Object same for into-array

zackteo10:05:43

On that note ... is this a typo on that page For example, byte arrays (byte-array []) have a type of "[B".

zackteo10:05:56

it is { instead of L

zackteo10:05:43

wait no, seems to be a different thing ... i think

didibus10:05:55

[B is array of bytes ya

didibus10:05:05

[L is array of reference to an object

didibus10:05:01

Try this syntax: ^"[Lorg....Constraints;"

zackteo10:05:10

It works! wow

zackteo10:05:58

But I don't really know why

zackteo10:05:25

But thanks! 🙂 I did think about changing it to a string when you gave that solution

didibus10:05:01

Apparently that's the default syntax, and all others are actually a short-hand to this one. I learned that as well, so thanks for asking

zackteo10:05:05

Hahaha tho not too sure this is level of interop with java is not the most common

zackteo10:05:22

Also, by any chance do you know what function I might want to use when a class I want to create has more fields than the constructor. Am currently using deftype

zackteo10:05:38

Am doing

(deftype ^{PlanningEntity true} Lesson [^Long id ^{PlanningId true}
                                        ^String subject
                                        ^String teacher
                                        ^String studentGroup
                                        ^{PlanningVariable "timeslotRange"} ^:unsynchronized-mutable ^Timeslot timeslot 
                                        ^{PlanningVariable "roomRange"} ^:unsynchronized-mutable ^Room room]
  ILesson
  (getId [this] id)
  (getSubject [this] subject)
  (getTeacher [this] teacher)
  (getStudentGroup [this] studentGroup)
  (getTimeslot [this] timeslot)
  (setTimeslot [this t] (set! timeslot t))
  (getRoom [this] room)
  (setRoom [this r] (set! room r))
  
  Object
  (toString [this] id))

zackteo10:05:12

But the equivalent part of the Java code is ...

@PlanningEntity
public class Lesson {

    @PlanningId
    private Long id;

    private String subject;
    private String teacher;
    private String studentGroup;

    @PlanningVariable(valueRangeProviderRefs = "timeslotRange")
    private Timeslot timeslot;
    @PlanningVariable(valueRangeProviderRefs = "roomRange")
    private Room room;

    public Lesson() {
    }

    public Lesson(Long id, String subject, String teacher, String studentGroup) {
        this.id = id;
        this.subject = subject;
        this.teacher = teacher;
        this.studentGroup = studentGroup;
    }

zackteo10:05:52

So i shouldn't have timeslot and room in the constructor which I understand is what deftype will do

didibus10:05:21

Hum... I don't know. Generally when I'm using a Java framework that expects me to pass it a Java class that derives from some of its class, Intend to just write it in Java and have it delegate to a Clojure namespace manually for cases where it gets hairy like this

zackteo10:05:43

Right :thinking_face: how does that work. I write the code as .java files?

didibus10:05:45

Your case is even worse haha cause the framework seems to expects annotations

didibus10:05:39

Well, so normally you can have a separate source folder for Java source, and then you need your build setup to compile the Java sources

zackteo10:05:52

Do I need to do any configuration in lein? Or can I just import the .java code hmmm

didibus10:05:57

But... I remember seeing a Clojure.lib that could be nice for this.

zackteo10:05:01

Wow, this is quite an undertaking ... let me try this out hmmmm

zackteo10:05:14

But thanks for the link and for the help!! 🙂

zackteo10:05:51

How one might want to do it within clojure still remains to be a question hmmm

didibus10:05:18

You can look here too, so this is how in the Java shim you'd call to Clojure: https://github.com/puredanger/clojure-from-java/blob/master/java/cfj/Support.java

didibus10:05:34

Using the Clojure Java API

didibus10:05:28

So the Java code is just a shell to please your Java framework, and then in the implementation for its methods you'd use the Clojure Java API to call into one of your own Clojure functions inside your own namespace.

zackteo10:05:11

Right hmmmmm

zackteo10:05:49

pretty intense stuff 😅

didibus10:05:50

Ya, sometimes some .framework have other ways not annotation based that are http://easier.to use.

didibus10:05:32

Not sure if Quarkus would. The downside is tutorials in Java tend to always show the annotation based approaches.mostly

didibus11:05:15

I can't seem to find the library I was thinking, it was basically a deftype that let you generate weirder Java classes

zackteo11:05:13

Right right hmmm

zackteo11:05:33

I was considering wrapping this library actually - at least for my own project purposes first ...

zackteo11:05:59

but seems like it is quite an endeavor and quite beyond my current skill level i think hmmm

didibus11:05:51

Oh it was this: https://github.com/athos/JiSE but it seems it doesn't support annotations

didibus11:05:25

Ya, that level of interop starts to require more knowledge of Java I think

didibus11:05:50

And Clojure as well hehe

zackteo11:05:30

Both of which I lack 😅 at least for now ... hahaha

valerauko11:05:45

I use (into-array LibraryClass my-vector)

zackteo11:05:48

How does LibraryClass work o: what is it?

zackteo11:05:33

@U0K064KQV also for such reasons, sometimes I wonder if I should take a deep dive into Java first to get a good foundation to do Clojure

valerauko11:05:00

I use this where the java interop requires LibraryClass[] and my vector is only instances of that class. (LibraryClass is just my filler name, https://github.com/valerauko/iny/blob/49cbe8266bd23eec1cbd5259244badee97a05426/src/iny/http2.clj#L57-L65)

zackteo11:05:43

Hmmm ... i see i see

zackteo14:05:53

Am proud to say I managed to get it working @U0K064KQV https://github.com/zackteo/optaplanner-clj

👍 3
valtteri16:05:25

I’m looking for a “smart way” to transform [0 2 5 10] into [[0 2] [2 5] [5 10]] where the tuples are always the “first and second”, “second and third”, “third and fourth” and so on. I’m pretty sure there’s some pretty way to accomplish this with core functions but so far I’ve only come up with ugly ways.

valtteri16:05:02

Vector is not a necessity

yuhan16:05:24

(partition 2 1 xs)

yuhan16:05:21

or perhaps (map vector xs (rest xs))

valtteri16:05:09

🙏 thanks!

valtteri16:05:25

TIL different arities of partition . Very handy

dpsutton17:05:57

Read the doc strings of partition and partition-all carefully

valtteri18:05:19

Yep. I’ve used partition previously for chunking but somehow missed how versatile it really is.

valtteri18:05:50

Docstring tells it all… As usual 😉

dpsutton18:05:56

Partition all will allow for smaller chunks at the end of you don’t have enough elements for a full partition. Very important if not dropping some elements is important

sova-soars-the-sora19:05:24

@UCPS050BV could you please explain this use of map vector ... ? I don't really understand how it works

yuhan02:05:20

(map (fn [x y] [x y]) 
     [1 2 3 4 5] 
     [2 3 4 5])
Is this any clearer? Check out the clojuredocs on map if you're not familiar with what it does for variable args :)

gorjusborg20:05:10

got a silly clojurescript question... why is there a need for (.field) and (.-field)? I though interop docs would explain the reason, but I still don't get it

phronmophobic20:05:18

One is calling the method named field and one is doing a field lookup. It's a cljs only feature since there's no similar ambiguity for interop on the jvm.

(.field obj)
;; equivalent js
;; obj.field()

(.-field obj)
;; equivalent js
;; obj.field