Fork me on GitHub
#babashka
<
2021-04-15
>
pez08:04:13

babashka.fs has file-name but no dir-name or am I missing something?

borkdude08:04:17

@pez

$ bb '(fs/file-name (fs/real-path "."))'
"babashka"
file-name just means the name part of a path

borkdude08:04:04

The docstring also says that: Returns the name of the file or directory.

pez08:04:54

Yeah, so it is like basename, right?

borkdude08:04:18

This naming is also used by the java.nio.file package itself: https://docs.oracle.com/javase/7/docs/api/java/nio/file/Path.html#getFileName() The functions in babashka.fs are usually named after those

borkdude08:04:08

I have seen different implementations of basename. Sometimes they do what fs/file-name do, but sometimes they also strip the extension. I follow java.nio.file as much as possible in babashka.fs.

pez08:04:28

I’m looking for the equivalent to dirname. Given a full path it returns the directory part of it:

$ dirname /Users/peter/Projects/my-proj/README.md
/Users/peter/Projects/my-proj

pez08:04:12

(Given a path to a directory it returns the parent directory. So seems like it uses the same semantics as babashka.fs/file-name)

borkdude09:04:34

@pez

$ bb '(fs/parent (fs/real-path "."))'
#object[sun.nio.fs.UnixPath 0x27773e47 "/Users/borkdude/dre/DocSearch"]

👍 3
sh5409:04:21

@borkdude Thanks for getting all the things for https://github.com/babashka/babashka/issues/784 in so fast! I was about to add the aset-byte and related functions by myself but you were too quick. I was writing a few tests for them at the same time so could always submit that. But I guess testing stuff defined via copy-core-var is fairly low value right? There are assumedly tests on the core functions which cover the logic

borkdude09:04:03

@slack1003 True. Unless you expect GraalVM to behavior potentially weird with these functions

sh5409:04:35

Dunno the GraalVM limitations well at all. All its doing is calling setByte (etc) on Array which surely graal can handle alright.

borkdude09:04:05

@slack1003 In #babashka-circleci-builds you can test the newest build from master

sh5409:04:48

@borkdude i’ll give it a quick run. so 76e2a241e767de2f38ac64c6f8a7e58be92fdd71 includes the latest sci changes then? Guess it gets triggered when sci updates?

borkdude09:04:03

@slack1003 it's triggered when I commit to babashka and I have committed the latest sci changes

sh5409:04:45

@borkdude yup works for me! only tested aset-byte on macos but all the others all go on the same principle

🎉 3
pez09:04:16

fs/parent seems to be what I was looking for.

bb '(str (fs/parent "/Users/peter/Projects/my-proj/README.md"))'
"/Users/peter/Projects/my-proj"

sh5410:04:47

hmm some funky behavior around combining print and System/exit. This program produces no output on my machine: #!/usr/bin/env bb (print "hello world") (System/exit 0)

sh5410:04:19

But will if println is used instead

sh5410:04:45

I have a case where I am just calling bb on a subprocess script and dumping output, err, and then exiting with the returned exit code

sh5410:04:03

and noted I was not getting output if I was using print

sh5410:04:53

though works fine if I call (flush)

sh5410:04:19

I literally never use print so not sure if this is normal behavior or bb specific

borkdude10:04:39

@slack1003 This is expected behavior, it behaves the same in Clojure

sh5410:04:00

k nice. never really use it so don’t remember the behavior. I added a flush to my stuff

littleli11:04:20

how much would including of java.security.SecureRandom add to a size of the babashka binary? DONE

borkdude11:04:33

@ales.najmann I just added that in 0.3.5 :)

littleli11:04:32

so hopefully, I'll have, in few days, an example of the partial homomorphic encryption scheme written for babashka

littleli11:04:04

but bear with me, I'm terrible coder.

borkdude11:04:20

babashka doesn't care about your coding skills

borkdude11:04:34

looking forward to it :)

borkdude11:04:09

bb 0.3.5 somewhat simplified my work bb.edn, by allowing to invoke tasks in parallel using #{p1 p2}, thanks @maxp https://gist.github.com/borkdude/35bc0a20bd4c112dec2c5645f67250e3#file-bb-edn-L17

Adam Helins16:04:19

To be more precise, @borkdude added support for ByteBuffer and all the typical classes that implement it. Hence this is more significant than just BinF. Just one example, @ericihli has recently announced a trie implementation that uses ByteBuffer. Well now who knows, maybe that kind of code can run in BB without any adaptation.

borkdude16:04:40

Do you have a link to it?

borkdude16:04:48

ok, that probably doesn't run as bb doesn't have deftype

Adam Helins16:04:58

It was worth a shot 😛 But point is, it probably opened the door for a new set of existing libs

borkdude16:04:10

yep, that's always nice :)