Fork me on GitHub
#babashka
<
2023-11-30
>
Price Smith04:11:05

Hi! I'm new to bb and to clojure, and kinda still green to programming in general. Came here after discovering Janet, super stoked about both! I've been a prolog person for some time and am mighty keen on diving into core.logic. Is this available in babashka? or just from graalvm? Both?

borkdude10:11:01

Currently bb doesn't support loading core.logic from source and it's also not built-in. You can just use regular JVM Clojure to try out projects that don't work with bb. Bb only supports a subset (albeit a large subset) of Clojure

Price Smith00:12:57

Thanks! Any plans to incorporate in the future? I suppose that's unlikely, cause not super commonly needed for a scripting lang?

borkdude12:12:22

So far no plans. What is your use case?

reefersleep11:01:37

I haven't really heard of anyone using core.logic for anything but personal growth. I thought I could use it to find combinations of X for a set of predicates Y, but it turned out (very early on, before even getting to any of the logic that I had planned to implement) that my set of X was way too large for core.logic to ever return a result, it just stalled forever. I had (naively) assumed that the results would be lazy, but they're eager. So I concluded (perhaps wrongly) that core.logic is only really good for those cases where you know in advance how many results there are, or when you know the result, like those logic riddles where "Jane has a hat that is not red, Jeff has a hat with a trim etc etc, who has which hat?". Which, in my view, is close to useless. Well, except for toying and experimenting, or if you would like a really odd syntax and adapting a whole different mindset for expressing small combinatoric sets. I'd love to be proven wrong.

Joakim Verona10:11:42

I'm having trouble with dynamic bindings.

(require '[babashka.cli :as cli])
(require '[clojure.string :as str])
(require '[taoensso.timbre :as timbre])
(import 'java.time.format.DateTimeFormatter
        'java.time.LocalDateTime)

(def ^:dynamic *foo* "foo root value")

(defn clone-and-build-repo []
  (println "(stdout) start, nothing should go to stdout")
  (let [writer  (  "/tmp/bindproblem.txt")]
    (with-open [out-writer writer]
      (binding [*out* out-writer
                *foo* "foo inside binding"]
        (timbre/info "out:" *out*)
        (timbre/info "foo inside binding:" *foo*)
        (try
          (timbre/info "this should go to the file  " )
          (println "this too")

          (throw (new Exception "an error im trhowing"))

          (catch Exception e
            ;;*out* seems to revert to default value here?
            (binding [*out* out-writer]
              (timbre/info "foo inside catch:" *foo*)
              (timbre/info "out:" *out*)
              (timbre/error e " not going to the file? it should!" ))
            )))))
  (println "(stdout) ... until now")
  (println "(stdout) start file content")
  (println (slurp  "/tmp/bindproblem.txt"))
  (println "(stdout) end file content")
  )

( clone-and-build-repo)
```

Joakim Verona10:11:44

the out binding doesnt work inside the catch statement, I find it odd.

Joakim Verona10:11:10

the foo binding seems to work though

borkdude10:11:33

Can you: 1 make a smaller repro if possible 2 test if the same works differently JVM Clojure and then come back?

borkdude10:11:49

you can print the dependencies used in bb with bb print-deps to create a clojure project with deps.edn

Joakim Verona10:11:40

behaviour is same in clojure

borkdude10:11:56

same as in bb? ok, then it's not a bb issue

Joakim Verona10:11:12

so I guess my mind is too small to comprehend dynamic bindings

borkdude10:11:23

let's see if I can understand it

borkdude10:11:12

can you still make a smaller repro is possible? then it will also become easier to understand with less dependencies :)

Joakim Verona10:11:26

this is smaller

(require '[taoensso.timbre :as timbre])

(def ^:dynamic *foo* "foo root value")

(defn clone-and-build-repo []
  (println "(stdout) start, nothing should go to stdout")
  (let [writer  (  "/tmp/bindproblem.txt")]
    (with-open [out-writer writer]
      (binding [*out* out-writer
                *foo* "foo inside binding"]
        (timbre/info "foo inside binding:" *foo*)
        (try
          (timbre/info "this should go to the file  " )
          (println "this too")

          (throw (new Exception "an error im trhowing"))

          (catch Exception e
            ;;*out* seems to revert to default value here?
            (timbre/info "foo inside catch:" *foo*)
            (timbre/info "out:" *out*)
            (timbre/error e " not going to the file? it should!" )
            )))))
  )

( clone-and-build-repo)

Joakim Verona10:11:00

smaller still?

borkdude10:11:06

can you do it without timbre?

Joakim Verona10:11:26

aha, timbre seems to be wonky

Joakim Verona10:11:57

this works as expected:

(def ^:dynamic *foo* "foo root value")

(defn clone-and-build-repo []
  (println "(stdout) start, nothing should go to stdout")
  (let [writer  (  "/tmp/bindproblem.txt")]
    (with-open [out-writer writer]
      (binding [*out* out-writer
                *foo* "foo inside binding"]
        (println "foo inside binding:" *foo*)
        (try
          (println "this should go to the file  " )
          (println "this too")

          (throw (new Exception "an error im trhowing"))

          (catch Exception e
            ;;*out* seems to revert to default value here?
            (println "foo inside catch:" *foo*)
            (println "out:" *out*)
            (println " not going to the file? it should!" e )
            )))))
  )

( clone-and-build-repo)

Joakim Verona10:11:46

I can rip out timbre from my main program. Still, weird why timbre should do this

borkdude10:11:48

perhaps ask in #C1J6MQC2H

😆 1
Joakim Verona10:11:16

thanks for the help!

👍 1
Alexander Kaiser15:11:48

I can't access files with a german umlaut in the file-path. Is this on purpose? Am i doing something wrong?

(fs/parent (fs/file "absolute-file-path-with-umlaut-äüöß"))
> Malformed input or input contains unmappable characters

(.exists (io/file "absolute-file-path-with-umlaut-äüöß"))
> false (even so the file exists. it's true for files that exist and do not contain a umlaut).
babashka 1.3.186, linux

borkdude15:11:49

can you please check with JVM clojure as well?

Alexander Kaiser15:11:01

in clojure:

(.exists ( "path-with-ö"))
true

borkdude15:11:07

works fine over here (on mac):

$ bb -e '(prn (fs/file "absolute-file-path-with-umlaut-äüöß"))'
#object[java.io.File 0x197c140 "absolute-file-path-with-umlaut-äüöß"]

borkdude15:11:45

is it possible to make a repro in a Docker image or so that I can run locally?

borkdude15:11:54

I'll try on linux when I get home

Alexander Kaiser16:11:12

~ $ bb -e '(prn (fs/file "absolute-file-path-with-umlaut-äüöß"))'
#object[java.io.File 0x74d4c381 "absolute-file-path-with-umlaut-????"]

Alexander Kaiser16:11:28

the umlauts are replaced with "?"

borkdude16:11:34

maybe this is only a printing issue?

delaguardo16:11:38

most likely this is due to system language encoding. You might need to set file.encoding=UTF-8

borkdude16:11:57

you can do so with:

bb -Dfile.encoding=UTF-8 ...

borkdude16:11:33

can you also try:

bb -e '(prn (fs/exists? (fs/file "absolute-file-path-with-umlaut-äüöß")))' 

Alexander Kaiser16:11:34

like this?

~ $ bb -Dfile.encoding=UTF-8 '(prn (fs/file "absolute-file-path-with-umlaut-äüöß"))'
#object[java.io.File 0x5d285dbb "absolute-file-path-with-umlaut-????"]

Alexander Kaiser16:11:49

bb -e '(prn (fs/exists? (fs/file "absolute-file-path-with-umlaut-äüöß")))' 
> false 

borkdude16:11:57

and does the file exist?

borkdude16:11:21

and what if you execute the above expression from a script foo.clj?

borkdude16:11:30

I want to exclude console reading/writing issues

borkdude16:11:40

and also try with/without the -D

Alexander Kaiser16:11:48

its the same. I first tried in emacs and then on the terminal.

borkdude16:11:02

ok, repro welcome in the form of a docker image

1
borkdude16:11:43

I also tried on my local linux system, could not reproduce

Alexander Kaiser16:11:00

I just figured it out: I because i installed bb with nix. When i install bb with yay (babashka-bin from AUR)everything works fine.

borkdude16:11:14

interesting

borkdude16:11:23

maybe make an issue with the nix folks

Alexander Kaiser16:11:52

I did reproduce that its not a problem with yay inside docker but i didn't get to reproduce the nix bb install inside docker.

Alexander Kaiser16:11:49

thank you very much for your help!

👍 1
Joakim Verona16:11:12

I would like to make something like a set of queues, but im out of inspiration how to do it properly. At the moment im using a simple futures based thing, that runs 10 builds in paralell, and then and then proceeds with the next 10 builds. I would rather split this into a queue for cloning things(this is the brittle step) and then build things as soon as the clone is done, also with a limit of maybe 32 in parallell. so its like 2 threadpools or something. But i dont know what threadpool/blocking queue, or whatever that works well with babashka? any hints would be apreciated

borkdude16:11:04

You can use a java.util.concurrent BlockingQueue directly or use core.async