Fork me on GitHub
#babashka
<
2023-10-12
>
borkdude09:10:07

My Windows machine is broken, so I can't test, but can someone please verify what this returns on a Windows machine in Clojure?

(System/getenv "HOME")
(System/getenv "USERPROFILE")
(System/getenv "userprofile")

mmer11:10:35

PS C:\Users\mmer> clj
Clojure 1.11.1
user=> (System/getenv "HOME")
nil
user=> (System/getenv "USERPROFILE")
"C:\\Users\\mmer"
user=> (System/getenv "userprofile")
"C:\\Users\\mmer"
user=>

borkdude11:10:06

are env variables case insensitive on Windows?

borkdude11:10:33

the clj PowerScript script checks for HOME in Windows first, but AFAIK this is not a Windows convention at all. Do you know the reason for this, @U064X3EF3?

elken11:10:57

Not a windows convention but its a common user convention to set it, tools like Emacs require it iirc

elken11:10:15

Cygwin might set it too

teodorlu11:10:56

anyone tried using babashka and/or sci to make a https://docs.racket-lang.org/pollen/ markup preprocessor for markup formats like markdown? I had this sudden urge to do something like

# my doc

◊(defn link [s] (str "[" link "](." link ")"))

- ◊(link "")
- ◊(link "")
then
$ cat doc | bb pollenish.clj | pandoc --from markdown --to html
. Markdown feels like toil sometimes.

❤️ 1
teodorlu11:10:05

a quick google search turned up https://github.com/JeremS/prose! It seems to mention sci. But from what I can tell, JeremS/prose is not an attempt to create a fast-starting bb script that one can use to preprocess.

teodorlu11:10:31

@U04V15CAJ you got it first 😄

borkdude11:10:48

I didn't have to search, because I knew it existed ;)

🎉 1
borkdude11:10:38

don't know if the code is bb-compatible but perhaps can be made so

👍 1
teodorlu11:10:57

from the readme it appears to already support sci. So perhaps an argument for supporting sci from Babashka scripts (which I believe has been discussed before). > don’t know if the code is bb-compatible but perhaps can be made so Using the eval evaluation strategy could potentially work from bb! I’ve gotta try this.

borkdude11:10:30

sci is already available in bb scripts

👀 1
respatialized15:10:44

Not quite pollen syntax, but my https://github.com/fabricate-site/fabricate also features the ability to embed arbitrary Clojure expressions. It uses a somewhat different evaluation model than prose. Not (yet) bb-compatible though!

👀 1
respatialized16:10:46

I definitely need to put more work into thinking about an extensible markdown-like syntax that: • Allows embedding Clojure expressions • Can be formally specified using EBNF I think there's potential for something that can be specified using a tree-sitter grammar, which would allow for support across tools (fabricate's notation currently relies heavily on an emacs package to work well in an editor)

teodorlu16:10:50

Right -- providing a good editor experience is a challenge here because we're no longer editing pure markdown, or pure clojure.

Noah Bogart14:10:06

Over in the github repo for #CLDK6MFMK, https://github.com/metosin/malli/pull/966#discussion_r1356842655 to add uri? support to malli.transform. They tried to use java.net.URISyntaxException, which failed in the Babashka tests. Are such exceptions something you're interested in supporting? Or should they just stick with Exception?

borkdude14:10:37

I'll add it to bb, but perhaps they can work around it using this for now:

#?(:clj 
  (defmacro if-exists [x y]
    (if (resolve x)
      x y)))
and then (throw new #?(:clj (if-exists java.net.URISyntaxException java.lang.Exception) ...) :cljs ...)

Noah Bogart14:10:00

they were trying to catch it, which makes that harder

borkdude14:10:44

ok, do the same but use if-exists in catch instead

👍 1
borkdude14:10:30

once the exception type becomes available in bb it will automatically use the more specific type

👍 1
borkdude14:10:34

and it will work with older bb's as well

borkdude14:10:09

added on master

Noah Bogart14:10:30

hot damn, thank you!

borkdude14:10:08

hmm, this doesn't work

(throw new (if-exists Foo Exception) "dude")

borkdude14:10:41

then just go for exception then in bb

borkdude14:10:10

and make a note that from 1.3.186 on the other type will work, and in a year time we can probably shift to that one

👍 1
borkdude14:10:25

so put a date in the comment ;)

borkdude14:10:16

or we can just shift to the new type once 136 comes out, people can still use the old malli version

Stig Brautaset15:10:14

👋 I tried this:

#?(:clj
   (defmacro if-exists [x y]
    (if (resolve x)
      x y))
   (defn -string->uri [x]
     (if (string? x)
       (try
         (URI. x)
         (catch (if-exists URISyntaxException Exception) _
           x))
       x)))
I'm getting a syntax error compiling the try, saying: Unable to resolve classname: (if-exists URISyntaxException Exception)

Stig Brautaset15:10:52

So maybe sticking with a plain Exception for now, and then revisit once 136 comes out?

👍 1
Noah Bogart15:10:04

i think that's smart

borkdude15:10:20

@U03N9E40Q2F yeah, let's do that.

Stig Brautaset15:10:21

I'll put a comment that it can be tightened up.

Matthew Twomey20:10:07

I’m missing something simple: (fs/list-dir "/tmp/" "**") or (fs/list-dir "/tmp/" "*") I’m trying to get the full recursive list

Matthew Twomey20:10:07

(fs/list-dir "/tmp/" "**/*" is also a no-go

borkdude20:10:19

you probably want glob, list-dir is not recursive

borkdude20:10:12

(fs/glob "." "**")

dpsutton20:10:39

the docstring made me think to use the “glob” style argument to fs/list-dir rather than the accept function style

dpsutton20:10:46

i didn’t realize it meant fs/glob

dpsutton20:10:48

babashka.fs/list-dir
([dir] [dir glob-or-accept])
  Returns all paths in dir as vector. For descending into subdirectories use `glob.`
     - `glob-or-accept` - a glob string such as "*.edn" or a (fn accept [^java.nio.file.Path p]) -> truthy

borkdude20:10:01

it doesn't mean fs/glob

borkdude20:10:18

but list-dir isn't recursive, glob is

borkdude20:10:35

list-dir does accept a glob pattern, like "*.clj"

dpsutton20:10:35

i get it now. but the reading made me think that (and i wasn’t aware of fs/glob)

Matthew Twomey21:10:00

but fs/glob returns an empty vector for me, for anything other that "."

Matthew Twomey21:10:21

e.g. (fs/glob "/tmp" "*") -> []

Matthew Twomey21:10:39

(fs/glob "/tmp" "**") -> []

borkdude21:10:41

@U0250GGJGAE You're hitting exactly a bug which has been fixed yesterday, namely when you query a root directory

🎯 1
borkdude21:10:10

another isue may be that /tmp is a symlink and fs/glob doesn't follow symlinks (yet)

(fs/glob (fs/canonicalize "/tmp") "**")
this now works for me with the version on master

Matthew Twomey21:10:28

Gotcha - yeah the canonicalize makes it work for me too. Thank you sir 👍

borkdude21:10:55

did you really want to query /tmp or did you try it as an example?

Matthew Twomey21:10:48

Was trying it as an example

Matthew Twomey21:10:01

I see now, that regular glob does work for non top-level

Matthew Twomey21:10:20

actually I need canonicalize for my use-case anyhow, so thanks for pointing that one out

borkdude21:10:26

can you explain why you need it?

Matthew Twomey21:10:08

Well I don’t need it. I just have some things mapped with soft-links and I prefer to refer to them that way.

Matthew Twomey21:10:56

(which then works fine if I canonicalize the target directory, which is a soft-link to somewhere else)