Fork me on GitHub
#babashka
<
2021-07-28
>
Stel Abrego00:07:04

I did the first 28 4clojure problems via 4bb to prepare for technical interviews. I got stuck on the Fibonacci problem because last was returning nil when it shouldn’t. Finally realized I had accidentally redefined last earlier in the repl session on an earlier problem 🥲😂

simple_smile 6
cfleming02:07:16

In bb, I’m getting Could not resolve symbol: *flush-on-newline* [at <repl>:1:1]. However I can see it being used in babashka here: https://github.com/babashka/babashka/blob/6d540e2f06acf086adebb2153e1b68a640e64012/src/babashka/impl/clojure/core/server.clj#L250. Is this flag supported in bb?

Bob B03:07:30

it doesn't look like that var is currently 'exposed' - as far as that usage, I think of it as almost two different contexts within the codebase - in my head, there's a "clojure context" where things get compiled and all the clojure vars are available, and there's the "sci context", where the vars available are basically those that are exposed by babashka namespace creation (that's my naive take on it)

Bob B03:07:03

so, https://github.com/borkdude/sci/blob/5ed2190f3c97de6d30f3aba96362bf6c68e95e90/src/sci/impl/namespaces.cljc#L741 maps all the symbols that are available in "clojure.core" within bb (as far as I know), and *flush-on-newline* isn't there

cfleming03:07:43

I see, thanks. I’ll have to look at how the bb prepl implementation works.

cfleming03:07:08

And it looks like the babashka.impl.* namespaces are not available at runtime either - so those are just compiled into the binary?

borkdude07:07:29

yes. babashka.impl is implementation anyway. These functions are exposed as different (non-impl) namespaces in bb. e.g. clojure.main is exposed to run a REPL. You can use prepl too.

borkdude07:07:51

NextJournal uses the prepl stuff for their purposes

borkdude08:07:05

Perhaps @U5H74UNSF can post the code they use in user space for the prepl in a gist?

cfleming09:07:50

In Cursive, when it connects to a socket REPL I send some code over to make the REPL work sort of like a prepl, but it’s structured in both directions rather than just one. I’m trying to reproduce that in bb which is where the series of questions are coming from.

borkdude10:07:44

issue(s) welcome. proxy support is currently quite limited due to restrictions in graalvm: we can't create new classes at runtime

borkdude10:07:58

if you can make multiple smaller issues with small repros, that would be helpful

cfleming10:07:18

I will do, thanks.

cfleming10:07:40

If you can’t create new classes at runtime, how does proxy work at all?

borkdude10:07:35

good question :) bb has intrinsified some usages of proxy so you should consider it unsupported, unless bb explicitly supports it for some use cases / libraries

cfleming10:07:38

Ok, I won’t file a bug about that one then

cfleming04:07:40

When I try to do the following: (proxy [Writer] []), I get this error: java.lang.IllegalArgumentException: No matching clause: [".Writer" #{}] user REPL:22:9. This is a simplified case, the real one has method implementations but that doesn’t make any difference to this problem. Any ideas?

cfleming04:07:43

The above two problems are because I’m trying to implement a basic REPL in userspace. One thing I would need for that is some way to load a file and supply a filename or path so that file and line metadata on the created forms is correctly established. I can’t find one - in Clojure I have to use Compiler/load but that’s not exposed for obvious reasons. Is there something I can use instead?

donavan09:07:51

I’m experiencing an issue in CI (Github actions) that I’m not locally. I’ve tried v0.4.0 and 0.5.0 with the same error. Any ideas before I debug further?

Could not find /home/runner/.deps.clj/1.10.3.822/ClojureTools/clojure-tools-1.10.3.822.jar
Attempting download from 
Cloning: [email protected]:<<internal-lib>>
Downloading: org/clojure/clojure/1.10.3/clojure-1.10.3.pom from central
Downloading: org/clojure/spec.alpha/0.2.194/spec.alpha-0.2.194.pom from central
Downloading: org/clojure/pom.contrib/0.3.0/pom.contrib-0.3.0.pom from central
Error building classpath. 
java.lang.NullPointerException
	at clojure.tools.deps.alpha.util.dir$canonicalize.invokeStatic(dir.clj:30)
	at clojure.tools.deps.alpha.util.dir$canonicalize.invoke(dir.clj:25)
	at clojure.tools.deps.alpha.extensions.deps$eval1390$fn__1392.invoke(deps.clj:27)
	at clojure.lang.MultiFn.invoke(MultiFn.java:244)
	at clojure.tools.deps.alpha$expand_deps$children_task__790$fn__792$fn__793.invoke(alpha.clj:403)
	at clojure.tools.deps.alpha.util.concurrent$submit_task$task__505.invoke(concurrent.clj:34)
	at clojure.lang.AFn.call(AFn.java:18)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
(updated to include the downloading of the clojure cli version, see below comment, I initially left out as it had the cloning of an internal repo)

donavan09:07:42

v.0.3.0 does not exhibit the error

borkdude09:07:44

Can you make a repro + issue?

donavan11:07:34

You’re welcome to trigger the CI job with different bb versions or tmate dubugging enabled BTW (if it’s possible for someone outside the org to do that)

donavan09:07:49

@U04V15CAJ thanks for taking the time to investigate. Apologies, I should have tried with just clj + git deps, I realise now I had introduced bb + git deps to the project CI at the same time and bb just happened to used first in the build.

borkdude09:07:06

no worries. were you able to find the issue?

borkdude09:07:34

I have much going on at the same time, sorry if I came across a bit blunt :)

borkdude09:07:46

I actually forgot we spoke on slack

donavan09:07:28

No worries! 🙂 Thanks for all your great tools, I’ve been bringing clj-kondo (+ clojure-lsp) and bb into our org recently and really enjoying it. I haven’t gotten to the bottom of it yet no, but it must be something missing from the Github actions environment or something

borkdude09:07:46

I could replicate your issue locally with a deps.edn + clojure

donavan09:07:59

Oh really, I couldn’t… strange

donavan09:07:29

It all works perfectly for me locally

donavan09:07:08

Oh wow, that’s very strange… on the real project it works locally but not in GH and on the repro project it doesn’t work locally for me either

borkdude09:07:18

perhaps you have and old clojure CLI install?

borkdude09:07:36

oh yes, on the repro project

donavan09:07:48

Pretty close to latest locally I think Clojure CLI version 1.10.3.855

borkdude09:07:56

but what is strange about the repro project is that you refer to the project itself in the deps.edn right?

donavan09:07:13

Yeah but the real project doesn’t do that but still fails with that error in GH

donavan09:07:42

(not deps.edn, just bb.edn in the repro)

donavan09:07:05

I’ll carry on debugging

borkdude09:07:36

try clojure + deps.edn in github perhaps

borkdude09:07:41

and see what happens

borkdude09:07:01

you can also set GITLIBS_DEBUG to true

borkdude09:07:07

then I believe it will print some stuff

donavan09:07:15

I’m just recreating the same failure with two projects instead of importing the same project

donavan09:07:24

cheers for that 👍

donavan09:07:42
replied to a thread:I’m experiencing an issue in CI (Github actions) that I’m not locally. I’ve tried v0.4.0 and 0.5.0 with the same error. Any ideas before I debug further? Could not find /home/runner/.deps.clj/1.10.3.822/ClojureTools/clojure-tools-1.10.3.822.jar Attempting download from <https://download.clojure.org/install/clojure-tools-1.10.3.822.zip> Cloning: [email protected]:&lt;&lt;internal-lib&gt;&gt; Downloading: org/clojure/clojure/1.10.3/clojure-1.10.3.pom from central Downloading: org/clojure/spec.alpha/0.2.194/spec.alpha-0.2.194.pom from central Downloading: org/clojure/pom.contrib/0.3.0/pom.contrib-0.3.0.pom from central Error building classpath. java.lang.NullPointerException at clojure.tools.deps.alpha.util.dir$canonicalize.invokeStatic(dir.clj:30) at clojure.tools.deps.alpha.util.dir$canonicalize.invoke(dir.clj:25) at clojure.tools.deps.alpha.extensions.deps$eval1390$fn__1392.invoke(deps.clj:27) at clojure.lang.MultiFn.invoke(MultiFn.java:244) at clojure.tools.deps.alpha$expand_deps$children_task__790$fn__792$fn__793.invoke(alpha.clj:403) at clojure.tools.deps.alpha.util.concurrent$submit_task$task__505.invoke(concurrent.clj:34) at clojure.lang.AFn.call(AFn.java:18) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) (updated to include the downloading of the clojure cli version, see below comment, I initially left out as it had the cloning of an internal repo)

v.0.3.0 does not exhibit the error

cfleming10:07:09

Does babashka (perhaps via tools.reader) support the :clojure.core/eval-file/`:line`/`:column` metadata?

borkdude10:07:34

@cfleming what is :clojure.core/eval- ?

borkdude10:07:13

I mean, it does support the location metadata, but not sure what eval is in this context?

borkdude10:07:23

You can try clojure.core/read-string perhaps in bb

cfleming10:07:13

Those are relatively new metadata that can be added to individual forms, for e.g. “Send top form to REPL”, to ensure that the forms get the correct location metadata.

cfleming10:07:20

I’m thinking about workarounds for the file load issue. I guess I could implement my own file load in bb using read and eval in a loop, but they’re form by form and won’t have the location metadata set if I understand correctly.

borkdude10:07:34

> I’m thinking about workarounds for the file load issue. What issue is this?

cfleming10:07:27

Edited, sorry - original link was bad.

borkdude10:07:31

@cfleming Doesn't load-file do this for you?

cfleming10:07:41

No, it doesn’t accept a file name.

borkdude10:07:28

I don't understand. The argument is a file name?

cfleming10:07:35

Actually, sorry - it does, but that’s not what you need over a REPL since it requires a local file. e.g. the nREPL :load-file op sends the file contents.

cfleming10:07:46

Sorry, been a long day and it’s getting late here.

cfleming10:07:53

If you want to be able to connect to a REPL on another machine, load-file doesn’t work. So what’s required is to be able to say “load this file’s worth of code I’m passing, and its filename for metadata purposes is xxx”

borkdude10:07:54

let's discuss separately in an issue perhaps, we'll come back to it

borkdude10:07:14

perhaps `(binding [*file ...

borkdude10:07:19

+ load-string ?

borkdude10:07:47

yeah, you could generate that expression perhaps

borkdude10:07:58

using binding + *file* and load-string

cfleming10:07:09

I’ll try that tomorrow and see how it works.

cfleming10:07:26

But the new metadata forms are useful for the case where you’re sending a single form but want the metadata to be right, e.g. you’re sending a single form from the editor to the REPL.

cfleming10:07:39

They were added quite recently to Clojure.

cfleming10:07:35

Because the previous hack that everyone did was to create a string with a whole bunch of newlines and then spaces and then the actual form, to get the form to start at the right line and column, and then to use Compiler/load

borkdude10:07:54

I didn't know about those vars

borkdude10:07:19

issue welcome

cfleming11:07:00

I can’t for the life of me find the JIRA discussing it.

cfleming11:07:57

Discussion here: https://github.com/cursive-ide/cursive/issues/2113. That’s actually the only place I can find any documentation about this. New in 1.10 apparently.

borkdude11:07:52

Cool! Can you post these links in an issue?

borkdude11:07:41

I was working on a new release of clj-kondo that can do macro-expansion: https://clojurians.slack.com/archives/C06MAR553/p1627470400150500 but I will read your issue later with more attention :)

cfleming11:07:03

I’ll try binding *file* and using load-string tomorrow, before filing anything about the file loading thing.