Fork me on GitHub
#babashka
<
2020-01-24
>
borkdude10:01:25

On master:

$ bb "(derive ::foo ::bar) (isa? ::foo ::bar)"
true

sogaiu11:01:13

working here:

$ ./bb "(derive ::foo ::bar) (isa? ::foo ::bar)"
true
are you working toward multimethod support?

nate15:01:03

@borkdude thank you for the inclusion of java.time in babashka, I'm using it to turn millis into human readable times in streaming data in my terminal

oskarkv18:01:14

When I use Thread/sleep or (shell/sh "sleep" "3") in babashka, and I try to run it through Linux Mint's "Startup Applications", it kills my script at the sleep. It doesn't happen with regular bash scripts containing sleep 3. Does anyone have any idea about what the difference is? The babashka script works fine in my terminal. I'm stumped.

borkdude18:01:32

@oskarkv does it also happen with clojure -e "(Thread/sleep 3000)"?

oskarkv18:01:34

No, that works, not killed

borkdude18:01:13

I have no clue.

borkdude19:01:59

@oskarkv How are you starting babashka? What if you wrap the call inside a bash script and call the bash script?

oskarkv19:01:17

@borkdude Nope, that doesn't work either.

borkdude19:01:19

no error message?

borkdude19:01:26

can you try with the --verbose flag?

oskarkv19:01:39

No error message. I don't know where they would appear. I looked in /var/log but nothing (with find . -mmin -1)

oskarkv19:01:47

Oh I'm stupid, I forgot to redirect the error stream

oskarkv19:01:06

Could not resolve symbol: sleep

oskarkv19:01:19

So, apparently my prelude doesn't run

borkdude19:01:21

Probably a quoting issue

borkdude19:01:47

ah you're using BABASHKA_PRELOADS?

borkdude19:01:06

that's picked up from the environment, so that might be an issue

oskarkv19:01:19

Yeah, that's almost certainly it

oskarkv19:01:55

Hm, how can I make it work outside of my shell? 😛

borkdude19:01:28

use a bash wrapping script?

borkdude19:01:36

and put it in bashrc or something?

borkdude19:01:42

(not sure how these config files work)

borkdude19:01:58

or maybe the linux mint thing accepts environment vars?

oskarkv19:01:20

Yeah, I'll look it up. Thanks for helping!

sogaiu21:01:10

i extracted the following cross-platform-ish which function from a project, and got to thinking whether it could run in babashka:

(defn which
  [bin-name]
  (let [paths (clojure.string/split (or (System/getenv "PATH") "")
                (re-pattern (.File/pathSeparator)))
        ;; for windows
        pathexts (clojure.string/split (or (System/getenv "PATHEXT") "")
                   (re-pattern (.File/pathSeparator)))]
    ;; adapted work by taylorwood
    (first
      (for [path (distinct paths)
            pathext pathexts
            :let [exe-file ( path (str bin-name pathext))]
            :when (.exists exe-file)]
        (.getAbsolutePath exe-file)))))
when i try to run it via bb, i currently get something like:
clojure.lang.ExceptionInfo: No matching method pathSeparator found taking 0 args

sogaiu21:01:03

is pathSeparator something that seems doable?

borkdude21:01:14

probably missing a reflection thing, but you can also do (System/getProperty "path.separator")

sogaiu21:01:26

ah, thanks -- i'll try that first

sogaiu21:01:08

works well on linux 🙂 will try windows next.

sogaiu21:01:14

seems to work on windows too. here's an updated version: https://gist.github.com/sogaiu/0c542ee238858adfe33f1200e3a86634

sogaiu21:01:47

@borkdude i looked at reflection.json -- for http://java.io.File here it has:

{
  "name" : ".File",
  "allPublicMethods" : true,
  "allPublicFields" : true,
  "allPublicConstructors" : true
}
at least some of oracle's docs list pathSeparator as a static field. my initial thought was that allPublicFields ought to cover it. does it seem like i'm missing something?

borkdude21:01:18

this does seem to work:

$ bb -e '.File/pathSeparator'
":"

borkdude21:01:52

I'm not sure why you were calling it as a method?

borkdude21:01:02

But that did seem to work in JVM clojure...

sogaiu21:01:24

ah, good point about calling as a method. don't know why i was doing that 🙂 it is a bit odd that that works in jvm clojure.

borkdude21:01:30

maybe because (. Classname staticField) works, and that's what it expands to. maybe I should support that in bb then... although maybe not

sogaiu22:01:53

my vote would be wait to decide -- if it comes up in some use case involving an existing library or something may be that's not a bad time to revisit?

borkdude22:01:45

maybe the Foo/bar syntax was introduced later?

borkdude22:01:00

maybe good to ask in #clojure to some clj historians

sogaiu22:01:26

perhaps after some grepping / rg-ing 🙂

borkdude22:01:59

@sogaiu I opened an issue and closed it again. It's just there for reference now, until we hit it as a problem: https://github.com/borkdude/sci/issues/257

👍 4