Fork me on GitHub
#babashka
<
2020-02-21
>
solf04:02:32

You don't use a repl workflow when writing babashka clj files, right?

solf04:02:46

I mean, there's no way to use CIDER (for example) with bb?

nate05:02:19

@dromar56 That would require nrepl, I believe.

nate05:02:38

And babashka does not have nrepl.

nate05:02:16

I've had some success developing bb scripts using a clojure workflow and then running them with bb.

nate05:02:54

That way I have my repl for dev and quick start up for prod usage.

solf05:02:08

I see, thanks.

solf05:02:38

I've seen inf-clojure (a lightweight version of cider) mentioned in bb github, I'll try it to see how it goes

stijn06:02:55

Yeah, I also use a normal clojure workflow with nrepl and then bb from the cli. It's generally not too hard to make everything compatible, since bb supports reader conditionals

Bobbi Towers06:02:55

I use babashka in my editor with a socket REPL and it is awesome

borkdude07:02:28

@dromar56 yep, socket REPL is the way to use bb with an editor

borkdude07:02:51

But first doing it in regular JVM Clojure also works.

solf07:02:57

socket repl with inf-clojure works well for evaluating expressions, however I can't seem to make auto-completion or documentation work

borkdude08:02:20

@dromar56 the latest release of Chlorine has auto-complete for bb.

borkdude08:02:13

I think editor tooling providers may or may not have implemented it for several REPLs. you could drop a message in #emacs or #cider to ask about this for inf-clojure

solf08:02:50

Thanks, I will dig a bit more into how Chlorine does it

mauricio.szabo13:02:17

Oh, I just saw that you posted on the channel already that you found 😄

borkdude08:02:27

It uses the most recently added ns-map function for autocompletion.

jeroenvandijk08:02:21

"I'll also shout out some people in the community that came up many times - Sean Corfield for his tireless library work and help for beginners, Daniel Compton for his work with Clojurists Together (and his many other efforts), and Michiel Borkent for his work on scripting and tooling around graal, clj-kondo, sci, etc. Kudos to them, and to anyone else I missed in the responses!" https://insideclojure.org/2020/02/20/clojure-survey/

🚀 8
👍 16
sogaiu09:02:25

> For the next Clojure version (presumably 1.11), we plan to fix the Graal locking issue

Crispin09:02:57

There might be more cloned borkdudes. Or he never sleeps. Or theres a time machine involved. The sheer amount of good stuff that keeps coming from him forces me to think of these possibilities...

😊 4
Mno09:02:55

Him and Sean are my role models, both so friendly and active.

😊 4
borkdude10:02:33

Any projects using sci that I should give a shoutout to in this slide?

🚀 4
borkdude10:02:42

@U066U8JQJ You might be working on something?

littleli10:02:40

isn't closh based on sci?

borkdude10:02:04

oh yes, I'll add it. it's work in progress using sci for native image

wilkerlucio11:02:20

@borkdude maybe in the future, currently just doing some experiments, but I'll let know if anything kicks off 🙂

solf10:02:59

I was able to setup inf-clojure to have auto-complete (via company) and show the arguments of the function in eldoc:

(use-package inf-clojure
  :ensure t
  :config
  (setq-default inf-clojure-repl-type 'clojure)
  (setq inf-clojure-completion-form
	"(clojure.core/let [collect (fn [x y] (clojure.core/map
				   (clojure.core/comp str first)
				   (x y)))
			   refers (collect clojure.core/ns-map *ns*)
			   from-ns (->> (clojure.core/ns-aliases *ns*)
					(clojure.core/mapcat
					 (fn [[k v]]
					     (clojure.core/map (fn [x] (str k \"/\" x))
							       (collect clojure.core/ns-publics v)))))]
		  (clojure.core/->> refers
				    (concat from-ns)
				    (clojure.core/filter
				     (fn [x] (re-find #\"%s\" x)))
				    (clojure.core/sort)
				    ))")

  (setq inf-clojure-arglists-form
	"(:arglists (meta (clojure.core/resolve (quote %s))))"))

👍 12
solf10:02:44

the completion form code was pretty much copy/pasted from chlorine

borkdude10:02:47

awesome! maybe we should put this somewhere in the babashka README

solf10:02:09

Indeed. The only thing is that I haven't taken the time to really understand what the completion code does (I'm not familiar with the different ns functions), it might be worth cleaning it up before putting on the readme

solf10:02:28

I can go over it during the week-end

mbjarland10:02:53

I have a feature request. Could we include java.time.temporal.ChronoUnit in the included classes in classes.clj ? We have LocalDateTime , LocalTime, etc and I’m trying to calculate millis between two dates using (.until localDateTime otherDateTime ChronoUnit/MILLIS) . If somebody has another way of calculating millis between two local date time instances without the CronoUnit requirement, any pointers would be much welcome.

borkdude10:02:33

hmm, there was someone who calculated millis a while ago.. I think that was @stijn

mbjarland10:02:46

ok, perhaps I just need to keep digging then

borkdude10:02:52

I wonder how he did it, but since java.time.temporal.ChronoUnit seems to be something we want to include, I'm ok with that

mbjarland10:02:23

there is also

long getLong(TemporalField field)
on LocalDateTime

stijn10:02:26

it was just for creating a date from unix timestamp

borkdude10:02:38

oh right, you needed long for that

borkdude10:02:13

@mbjarland PR welcome for the missing class

borkdude10:02:30

you can fetch a new build from #babashka_circleci_builds when it gets merged

borkdude10:02:36

to test it out

borkdude10:02:47

a unit test for it would also be nice

mbjarland10:02:15

and just so I’ve said it, babahska is awesome and I have to say I’m quite impressed by the level of progress on this project

mbjarland10:02:01

I just finished writing a jstack thread dump analyzer command line script using babashka, does transitive lock analysis and prints out a report with colored ascii trees and tons of stats etc…quite nice

sogaiu10:02:27

pics pics!

borkdude10:02:30

thanks a lot! if there's any examples that we should link to from the README, I'd be happy to include it

borkdude10:02:59

or if it's something that's useful in general, you can PR it into the examples directory of the repo with a small description in the README in the Gallery section

mbjarland10:02:55

hmm…I’ll have to mull that over. Code written in the context of a client project, need to meditate on what I can and can not share

borkdude10:02:32

No worries, don’t feel obliged to anything.

souenzzo11:02:25

Hello. Mostly for learning proposes, how do I debug this:

$ cat deps.edn 
{:deps {com.cognitect.aws/api       {:mvn/version "0.8.437"}
        com.cognitect.aws/endpoints {:mvn/version "1.1.11.722"}
        com.cognitect.aws/s3        {:mvn/version "784.2.593.0"}}}

$ CLASSPATH="$(clojure -Spath)"
$ rlwrap bb --classpath "$CLASSPATH"  --repl
Babashka v0.0.71 REPL.
Use :repl/quit or :repl/exit to quit the REPL.
Clojure rocks, Bash reaches.

user=> (require '[cognitect.aws.client.api :as aws])
No matching clause: :use [at cognitect/aws/client/api.clj, line 4, column 1]
This line/column don't look right.

borkdude11:02:32

@souenzzo babashka honors the BABASHKA_CLASSPATH env variable. it's unlikely that aws.client.api works out of the box with babashka, since it's quite a complex project. it doesn't even compile with GraalVM itself 🙂

souenzzo11:02:46

Yeah sure. But my point is more about "how to debug/find limitations" or "why it say about this line" (this line is a (ns ... line

borkdude11:02:13

@souenzzo You can find a stacktrace with bb --verbose

borkdude11:02:22

libs that do work with babashka are listed here: https://github.com/borkdude/babashka/#tools-and-libraries

borkdude11:02:41

JUXT wrote a blog post about babashka! https://juxt.pro/blog/posts/babashka.html

🚀 12
🎉 4
Mno11:02:47

That's so cool

nate14:02:53

Wow, that is an epic doseq call.

borkdude15:02:41

I'm glad it worked 😛

mbjarland15:02:12

I did not know doseq worked like for comprehension with :let , :when etc

borkdude15:02:59

yeah, I also discovered that later on. one other difference with for is that doseq accepts multiple exprs, like when

mbjarland15:02:44

@borkdude nice! and thank you, it could be argued I should have done that

borkdude15:02:58

( I tried to push directly to your PR, but that didn't work ) - no problem!

borkdude16:02:48

sci as a slack bot using a google cloud function: https://twitter.com/borkdude/status/1230886396551929857

sparkofreason16:02:47

That article from JUXT gets me thinking - make is cool, but Makefile's are fiddly and arcane. Anybody ever think of using babashka to transform an edn file to a makefile?

jeroenvandijk18:02:22

Sounds like a good idea!

borkdude16:02:04

bake 🙂

12
nate16:02:46

@borkdude I tried using when-some in a bb script and noticed it didn't exist. Would that only involve a change to sci? I found where when-let is defined.

jeroenvandijk16:02:32

A change in Sci and then a submodule update in Babashka. But it starts with a commit in Sci

jeroenvandijk16:02:17

I guess you only need to add when-some here https://github.com/borkdude/sci/blob/cdca1bc28b071163333b6c352430cec544c3c5ae/src/sci/impl/namespaces.cljc#L141-L153 Then it would be automatically included. For normal functions it works slightly different

borkdude17:02:22

@nate jeroen is right, it should be implemented right there along with the others. PR welcome!

nate17:02:14

working on that right now, getting the lay of the land

borkdude17:02:09

@nate usually I just copy the implementation from clojure.core

nate17:02:22

PR submitted

nate17:02:32

TIL about when-first

borkdude19:02:07

that's certainly helpful

borkdude19:02:39

let me get the clojure.data.xml branch up to date

borkdude19:02:31

the clojure.data.xml branch has been made up to date. in a few minutes there will be binaries to test out in #babashka_circleci_builds

borkdude19:02:08

at least this works on my machine:

$ ./bb '(clojure.data.xml/parse-str "<foo></foo>")'
#xml/element{:tag :foo}

borkdude19:02:24

$ ./bb '(clojure.data.xml/emit-str (clojure.data.xml/parse-str "<foo></foo>"))'
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><foo/>"

borkdude19:02:25

so does that what you want?

borkdude19:02:24

not all of the API functions are in there yet, if you need more than feel free to add more to the branch

borkdude19:02:44

but I assume parsing from and generating to strings is what most people do

borkdude19:02:53

some people also use zippers I guess

borkdude19:02:04

note: I've never used zippers for xml editing, I usually do it "by hand"

borkdude19:02:33

$ ./bb '(clojure.repl/dir clojure.data.xml)'
element
emit-str
parse-str

jeroenvandijk22:02:24

I'm trying a file watcher with Graalvm (maybe useful for babashka too). Any idea how to solve an error like this?

Exception in thread "main" java.lang.IllegalArgumentException: Class java.nio.file.StandardWatchEventKinds$StdWatchEventKind[] is instantiated reflectively but was never registered. Register the class by using org.graalvm.nativeimage.hosted.RuntimeReflection
	at com.oracle.svm.core.genscavenge.graal.AllocationSnippets.checkArrayHub(AllocationSnippets.java:182)
	at clojure.lang.RT.seqToTypedArray(RT.java:1753)
	at clojure.core$into_array.invokeStatic(core.clj:3454)
	at clojure.core$into_array.invoke(core.clj:3443)
	at juxt.dirwatch$register_path.invokeStatic(dirwatch.clj:38)
I've tried adding several variations of adding java.nio.file.StandardWatchEventKinds$StdWatchEventKind[] to the reflection file without success

jeroenvandijk22:02:44

The above is the output of the native image btw

borkdude22:02:01

what is the [] at the end?

jeroenvandijk22:02:13

Not sure but this is the definition (a private class)

private static class StdWatchEventKind<T> implements WatchEvent.Kind<T> {
   84           private final String name;
   85           private final Class<T> type;
   86           StdWatchEventKind(String name, Class<T> type) {
   87               this.name = name;
   88               this.type = type;
   89           }
   90           @Override public String name() { return name; }
   91           @Override public Class<T> type() { return type; }
   92           @Override public String toString() { return name; }
   93       }

borkdude22:02:14

@jeroenvandijk I think I would check that lib for reflection warnings, that's probably causing this

jeroenvandijk22:02:21

Yeah i think you are right

jeroenvandijk22:02:25

Thank you 🙂

borkdude22:02:47

@jeroenvandijk we already have some functions around waiting for things here: https://github.com/borkdude/babashka/#babashkawait it doesn't use a file watcher, it's just polling

jeroenvandijk22:02:25

I want to have a webserver with live reload like functionality. I hope that this library will help me with that. Let's see if I can get rid of the warnings

jeroenvandijk23:02:59

Ok compiles runs now. Not the results I expect yet. Maybe something internally goes wrong

ambrosebs23:02:06

this is the coolest damn sounding project ever

👍 28