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?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').
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?
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.
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)?
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.
Extremely basic VM question: They can be persistent (or rather save state) across restarts/sleeps/userchanges of the host system, yes?
Yes. That's essentially what WSL2 is: a VM.
So between a VMWare VM and WSL2...?
@factorhengineering 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.
(and with VS Code, at least, you can have a full Windows-native editor experience while still having everything running on WSL2)
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.
How does one navigate to the Windows file system from the WSL2 Ubuntu CLI?
/mnt/c
is your C: drive.
Nice and simple. Thanks!
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.
(1) was easy: just launch the Ubuntu Windows app a 2nd time for a 2nd CLI
Or use Windows Terminal and have them tabbed
(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.
Windows Terminal will not offer me that option. Only command prompt, powershell, and some azure thing.
I thought it offered the WSL2 option after I first installed it a while back, but if it ever did it has since disappeared.
It definitely should list all distros installed. In the dropdown and you should be able to configure your default.
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
@seancorfield had recommended VcXsrv, but I thought I heard bad things about SourceForge a while back, and X410 is available as a Win10 app. Hmm...
@factorhengineering It seems you're not alone with the disappearing WSL profiles in the Windows Terminal. https://github.com/microsoft/terminal/issues/6946
Aha. Glad to know it's not something I messed up.
Looks of useful information about workarounds in that issue. Interesting stuff.
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.
@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
I am not sure what are you trying to achieve. Setup a website?
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.
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.
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.
@factorhengineering do you have a ClojureScript REPL/editor all setup?
I have Doom Emacs. Not overly familiar with it, but again I'm trying to up my game.
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?
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.
Sorry, I can’t really help with Windows specifically… Last time I used Windows it was in 2009 or so 🙂
Using MacOS, but can help with Linux basics as well.
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.
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.
I mean I'll be running my Emacs in Windows, but operating on files in the WSL2 (Ubuntu) subsystem.
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
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 @seancorfield advised me months back (but only a small step ago since I was derailed. Does that sound about right, @raspasov?
@factorhengineering 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.
I suspect with Emacs, you'll need to run it on WSL2.
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.
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.
Do you like Emacs? What other editors are you familiar with?
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.
Clojure sort of expects you to do everything from a terminal 🙂
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.
As I said above, if you're comfortable using VS Code on Windows, it has an extension that makes the whole WSL2 thing seamless.
I haven't used Emacs for five or six years now (but used it on and off for about twenty years prior to that).
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.
Pretty much everything in the Clojure world assumes you're either on macOS or Linux. If you're using Windows, it's painful.
...and I was just starting to get comfortable with Doom Emacs, and hoping I could finally, you know, write some code. Ha 😭
I thought at least my text editor and my browser could still be in Windows. Guess not?
If I had known that, I might have just set up dual-boot instead of WSL2.
You can use VS Code on Windows and have your whole dev env running on WSL2 ¯\(ツ)/¯
What is the advantage of WSL2, then? Just being able to alt-tab to Windows stuff completely unrelated to the task of programming?
WSL2 means you can do all your development on Linux while keeping your familiar Windows UI and apps.
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?
Because the VS Code bridge to WSL2 is modern and Emacs is not modern?
Well anyway, I guess I've done all the set-up except installing Doom Emacs. I should find out how difficult it is.
Your choice 🙂
I really wish the Ubuntu in WSL2 was the standard GUI kind. Why would be a stripped-down CLI-only thing??
Does it have to be?
Linux (and Unix before it) were all originally non-GUI. GUIs are way over-rated.
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.
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 🙂
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).
It's not really missing anything.
Why would it not just look like the other 3 or 3 times I've used Ubuntu?
3 or 4
Windows just didn't support WSL2 GUIs until these recent Insider builds.
A Ubuntu live CD will boot directly into a GUI, from my experience. Why would the WLS2 version be different?
They're not even comparable.
strange. They should at least have a modified name for it. ...Ubuntu-CLI
WSL2 runs user-mode Linux distros. Not just Ubuntu.
user-mode?
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.
https://docs.microsoft.com/en-us/windows/wsl/tutorials/gui-apps
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?
That's a window manager/shell. It's just an app.
The "OS" doesn't have a GUI.
Oh wait...I see an actual desktop there. Would not have called that an 'app'.
That article shows the Windows desktop, running several Linux GUI apps. Not a Linux window manager/desktop.
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.
I would never have considered the actual menu or file explorer 'apps', but I guess one could.
Oh. OK
Sounds like they're almost there. Ha.
The latest builds have full sound and video integration between Linux and Windows. It's pretty impressive.
I have Google Chrome (Linux) installed and it behaves just like a Windows app in terms of launching it from Windows -- or from Linux.
I run Reveal from my Clojure REPL and it pops up as a (Linux) GUI.
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.
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.
That article explains how to install Google Chrome or Microsoft Edge on WSL2.
...though I would have guessed maybe something like localhost:9000 in WSL2 might be visible in Windows too.
(but you'll need to be on recent Insider builds)
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. 😕
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".
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?
ClojureScript starts Google Chrome (on WSL2) for me -- either via the quick start or figwheel or shadow-cljs
No, I'm not saying that.
I mean assuming I'm using Emacs and not that specific VSCode functionality.
The quickstart isn't doing it.
I have no idea how to get Emacs-on-Windows to talk to the WSL2 filesystem.
I just ran
clj --main cljs.main --compile hello-world.core --repl
Of course it isn't: you don't have an X Windows server running on Windows to support GUI apps on WSL2 do you?
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.
I'm not worried about the editor just yet.
I've set up the quick start stuff just using vim on WSL2
So I also tried this (since no browser auto-opened), but how can I launch one?
If you are running Linux and the REPL does not start, try disabling browser auto-launch and opening <http://localhost:9000>
manually:
clj --main cljs.main --repl-opts "{:launch-browser false}" --compile hello-world.core --repl
Because from the Windows side, WSL2 is not "localhost", it has it own IP address.
How can a person launch anything when the CLI has been taken over by a REPL anyway??
Run multiple terminal windows?
That makes sense. But what about a WSL2 browser?
Seems like one was supposed to auto-launch with the first command.
Microsoft's new Terminal has tabs which is what I use.
Do you have an X11 server installed on Windows?
I did install that, but it is only offering me PowerShell, Command Prompt, or some Azure thing....no WSL2 as promised.
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.
Install Terminal, I mean.
No idea about an X11 server.
VcXsrv...ok
When I installed it, Ubuntu (WSL2) was available in Terminal. I edited the Terminal config to make it the default.
I just found this. I might try it tomorrow:
https://www.reddit.com/r/linux/comments/ii79t0/wsl2_gui_using_vcxsrv_complete_guide_for_beginners/
Here's my new tab menu in Microsoft Terminal:
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.
Life as a software developer. Always new hills to climb.
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.
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 🙂
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.
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.
Clojure isn't easy to work with. None of its tooling is designed to be easy. And Windows just makes things harder.
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.
I'm not seeing any point of sticking with Windows now
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.
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.
I would never have considered Windows as a development platform if it wasn't for WSL.
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.
...or does it have to?
But I want a non-Linux desktop OS because the UX is just so much better than Linux's weird window managers etc.
I thought it would be as simple as shadow.cljs (or Leiningen and figwheel-main) and Emacs+CIDER and good to go.
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.
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.
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?
I think you just answered my question while I typed it.
From the 2021 State of Clojure survey results:
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.
Windows was designed for consumers, not programmers.
Hey 4.77%. I wonder what they do?
Microsoft are doing great work these days making Windows viable for programmers.
Well, I assume it’s decently supported for C# stuff? (I have never used C# professionally, that’s just an assumption)
Sure, with fancy button-clicking UI-based IDEs.
I'm not married to Windows. I've had (secondary) computers running only Ubuntu before (GUI though). My opinion regardless.
Yeah maybe it's just my dumb luck I came down to a programming language that is extra hostile to Windows.
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”
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.
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.
Well I'm going for ClojureScript, not Clojure. Does that matter?
I’ve seen the “problems” most other people run with in other editors and I just shake my head 🙂
Yes, that’s supported also.
And you're running that on just a GLinux machine?
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.
MacOS
Ah. Same thing when it comes to all these programming tools, though, yes? *nix?
@seancorfield What specifically do you not like about it? (I realize, it needs a fast computer with a lot of RAM)
Yeah, macOS is far and away the easiest setup for Clojure and ClojureScript. Pure Linux is probably second easiest. Windows is just hard.
@raspasov I'm not much of a fan of IDEs at all and I just find IntelliJ to be slow and bloated and weirdly organized.
That's sad if true. Most difficult OS to get is the easiest to use for this?
I've never liked its UI. I preferred Eclipse over IntelliJ (and I don't like Eclipse much either).
macOS is easy to get. It's just expensive 🙂
Should I just try to run MacOS instead of Ubuntu on this ThinkPad? LOL
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:
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.
MacOS on ThinkPad…. I can sense that can be another week-long project 🙂
Yeah I'm on a nvm-e drive here, so no go for MacOS?
(I would say no, unless you’re just keen on tinkering)
'week-long' would be a fantastic relief at this point. 😕
So anyway, how long should I give that to-do list above before throwing in the towel on WSL2 and just dual-booting?
Yes, I heard M1 had some problems, but anecdotal reports say most things work already; But I have no first hand experience (yet).
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
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.
Here's what my Clojure dev looks like on Windows/WSL2 with Reveal:
That's VS Code native on Windows, Reveal running as an X11 app and a Socket REPL started from the command-line in Ubuntu.
Reveal? New terms today: x11, vxm..whatever that term was, and reveal.
I used Cognitect's REBL before that for visualizing results of evalutions.
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.
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.
The disruptor I think is meant to be used with mutable objects to save on object allocation
So I don't think you can use it with Clojure immutable data-structures
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
@didibus 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 ?
@didibus Also what did you mean by "clearing it after use" ? did you mean to clear the offsets on the ring-buffer ?
Thank you @didibus
The data isn't copied off heap
It's more like an EventPool similar to having a ThreadPool
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.
When you publish to the Ring Buffer, you reuse the event objects already in it, so they have to be mutable
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.
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
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 fromBut you're not dealing with Clojure data-structures at this point, you've got your own custom memory layout and structure.
Or you can use only primitive fields on your Events.
[L means it's an array of org.opr...
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)]))))
So defineConstraints expected an array of Constraints but you gave it a single instance of Constraints instead
right hmmm
What should the type hinting be then ? 😮
Like how do I translate this type Constraint[]
?
Exactly what the message says
^[Lorg....
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)]))))
right?
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
Hum... ok ya that was a guess of mine haha
I think you might not need a hint
But you need to use the array function that takes a class
into-array
I believe
No worries 🙂 understanding the L
part was helpful! May I know how you knew about it? Or just something to remember
https://clojure.org/reference/java_interop See Aliases it briefly mentions it and links to the Java doc for the various letters following [
the issue is that object-array
will end up getting java.lang.Object
same for into-array
On that note ... is this a typo on that page For example, byte arrays (byte-array []) have a type of "[B".
it is {
instead of L
wait no, seems to be a different thing ... i think
[B is array of bytes ya
[L is array of reference to an object
Try this syntax:
^"[Lorg....Constraints;"
It works! wow
But I don't really know why
But thanks! 🙂 I did think about changing it to a string when you gave that solution
The answer here is why I told you to try this: https://stackoverflow.com/questions/59450366/is-it-possible-to-type-hint-a-clojure-array-filled-with-a-deftype-object
Thanks!!
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
Hahaha tho not too sure this is level of interop with java is not the most common
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
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))
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;
}
So i shouldn't have timeslot
and room
in the constructor which I understand is what deftype
will do
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
Right :thinking_face: how does that work. I write the code as .java
files?
Your case is even worse haha cause the framework seems to expects annotations
Yup
Am following this https://quarkus.io/version/1.7/guides/optaplanner
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
Do I need to do any configuration in lein
? Or can I just import the .java code hmmm
But... I remember seeing a Clojure.lib that could be nice for this.
Ya you do
https://github.com/technomancy/leiningen/blob/master/doc/MIXED_PROJECTS.md
Wow, this is quite an undertaking ... let me try this out hmmmm
But thanks for the link and for the help!! 🙂
How one might want to do it within clojure still remains to be a question hmmm
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
Using the Clojure Java API
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.
Right hmmmmm
pretty intense stuff 😅
Ya, sometimes some .framework have other ways not annotation based that are http://easier.to use.
Not sure if Quarkus would. The downside is tutorials in Java tend to always show the annotation based approaches.mostly
I can't seem to find the library I was thinking, it was basically a deftype that let you generate weirder Java classes
Right right hmmm
I was considering wrapping this library actually - at least for my own project purposes first ...
but seems like it is quite an endeavor and quite beyond my current skill level i think hmmm
Oh it was this: https://github.com/athos/JiSE but it seems it doesn't support annotations
Ya, that level of interop starts to require more knowledge of Java I think
And Clojure as well hehe
Both of which I lack 😅 at least for now ... hahaha
Thanks This helped a lot
I use (into-array LibraryClass my-vector)
How does LibraryClass
work o: what is it?
@didibus 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
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)
Hmmm ... i see i see
Am proud to say I managed to get it working @didibus https://github.com/zackteo/optaplanner-clj
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.
Vector is not a necessity
(partition 2 1 xs)
or perhaps (map vector xs (rest xs))
🙏 thanks!
TIL different arities of partition
. Very handy
Read the doc strings of partition and partition-all carefully
Yep. I’ve used partition
previously for chunking but somehow missed how versatile it really is.
Docstring tells it all… As usual 😉
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
@qythium could you please explain this use of map vector ...
? I don't really understand how it works
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
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
thanks