given https://clojurians.slack.com/archives/CLX41ASCS/p1614426753131400?thread_ts=1614417434.128100&cid=CLX41ASCS limitation, is there a way to implement a custom map type in Babashka?
@wilkerlucio What would you need to implement this? reify + ILookup + ...?
but also IFn
, to make (map :key)
and what about assoc etc?
yeah, all of those, in the CLJ side I'm currently using Potemkin, but there he also takes care of a lot of Java specific interfaces that I believe are unescessary in Kondo
for CLJS there also a few different protocols, so I'm not sure the exact list needed for babashka*
kondo?
ah
this is what I have (clj using Potemkin / CLJS manually): https://github.com/wilkerlucio/pathom3/blob/master/src/main/com/wsscode/pathom3/interface/smart_map.cljc#L291-L390
Can you clone babashka locally?
And then the branch custom-map
.
$ clojure -M:main -e '(def m (reify clojure.lang.ILookup (valAt [this x] (str "->" x)))) (:foo m)'
"->:foo"
Clone using the --recursive
option
so, my guess here is that I may be able to almost fulfil the complete contract, just not the IFn
part?
$ clojure -M:main -e '(def m (reify clojure.lang.IFn (invoke [this arg] (str "arg->" arg)))) (m :foo)'
"arg->:foo"
The way it's currently set up it only supports one arity but I think I can change this
cool, working on other things now, but I'll give a try on that, thanks!
I fixed the arity problem locally. Any more interfaces you need?
I'm about to cut a release
sorry, cant check now
go ahead with the release 🙂
I've got ILookup and IFn working now for all arities
Hi everyone, I'm currently trying to use records in babashka but they don't seem to work. The documentation says that the implementation is different from clojure but that it should work as expected. In the example bellow the messages are never printed. Am I doing something wrong? Should I open a bug or is this a know limitation? Thanks
(defprotocol Task
(test [this])
(test2 [this]))
(defrecord TaskImpl [a b]
Task
(test [this] (println "It should be printed"))
)
(defmethod test2 TaskImpl []
(println "It should be printed")
)
(let [ t (->TaskImpl "a" "b") ]
(.test t)
(.test2 t))
@luis559 Made it a little bit linter proof ;). Note that you can just call the methods by name, you don't have to use .test
, although we could probably make that work
(ns foo (:refer-clojure :exclude [test]))
(defprotocol Task
(test [this])
(test2 [this]))
(defrecord TaskImpl [a b]
Task
(test [_] (println "It should be printed (proto)")))
(defmethod test2 TaskImpl [_]
(println "It should be printed (mm)"))
(let [ t (->TaskImpl "a" "b") ]
(test t)
(test2 t))
It should be printed (proto)
It should be printed (mm)
Thanks. Let me try it again.
@borkdude Thanks. I managed to get it to work. I figured out what my problem was. I was not able to call methods my name like you suggested because I forgot to import them. I guess the biggest difference between the 2 approaches would be weather or not you one needs to import the methods. To make sure my library is compatible with clojure and babashka I have to make sure I don't use the dot syntax.
Apologies if I missed something obvious in the docs - how can I have a script I am writing return a non-zero exit code?
I'm giving babashka a whirl for the first time today, writing a little helper script so I can have one command to properly pick the right command for unpacking a given file. I've googled "tar gz command line options" more than I care to admit, and then today downloaded something that was .tar.xz. Figured it was time to scratch the itch. I've called it bunpack
🐰 🫓
doh. Never fails, ask a question publicly, find your answer immediately thereafter. I believe System/exit
is what I needed
@robertfrederickwarner That's it and don't worry, feel free to ask anything here
Thanks @borkdude. Your prolific work astounds! I always loathed writing bash scripts, this is a wonderful addition to the ecosystem
This looks exciting, thanks for making it babashka compatible @luis559 :)
Thank for helping and sorry misspelling babashka. ;)
binary: "/usr/bin/ffprobe"
args: [:show_format :show_streams "<http://ftp.nluug.nl/pub/graphics/blender/demo/movies/ToS/ToS-4k-1920.mov>"]
task: {:ss nil, :ex #error {
:cause "error=2, No such file or directory"
It's probably best to look on the path for ffprobe?I will update the docs. But if you remove the binary name it will use whatever is available in the path.
Ah I didn't know that, thanks.
Used Babashka over cgi to create a really basic line art svg generator https://cgi.eccentric-j.com/lineart/lineart.svg?bg=000000&fg=ffffff
https://github.com/eccentric-j/clj-lineart src if anyone’s interested in how it works
It did bring about some rough edges I’m trying to come up with better solutions for. The first one is the shebang for the entry point script.
#!/home1/<username>/bin/bb
makes it less portable. If I could set the PATH variable then I could use #!/user/bin/end bb
but unfortunately cgi is pretty locked down so most environment variables are stripped away if set with Apache (according to my research and tests). I’m wondering if I could write a script that behaves like env
that will set the path, point to bb, and perhaps supply the src dir relative to the entrypoint script.
@jayzawrotny this is cool! If you plan to expand on the idea with more SVG elements, my library https://github.com/adam-james-v/svg-clj might be interesting to you. I'm working hard to get it polished, but some of the functionality might be useful to you as is.
That’s really cool! I foresee making more generative art experiments in the future. Thanks!
Then at least it would be like #!../../bin/devenv bb
which is a bit easier to replicate in a local docker for development or move to another server.
@jayzawrotny Maybe you can str/replace the shebang once you deploy the script to bluehost?
Is it possible to set the interpreter in the cgi config (for a certain file extension)? (sorry, no idea, I haven't used this myself)
As far as I found I can only modify a .htaccess to specify:
AddHandler cgi-script .clj
So that apache knows what to do with requests for that file.There’s also some runtime config that would be nice to automate so I think a wrapper script would be a reasonable approach
Yeah, so maybe making a before-deploy hook which rewrites your script just in time, will work
ah I see
yeah, you could write a little bash wrapper
Deploys are pretty primitive right now, sometimes SFTP, sometimes rsync, sometimes scp
Is there a way to load code from a local file not on the classpath? Maybe load-file
?
Yep, that's the one
Any suggested exemplars for a published babashka script intended for use on the command line? I pushed my little bunpack script up onto github, if anyone has use for it or any suggestions for how to package it in a nicely reusable form. https://github.com/robertfw/bunpack
You could use a shebang so you don't need the bash wrapper:
#!/usr/bin/env bb
I meant to be learning CLJS today. I started installing shadow-js and got to the "install node" step, had to google "extract tar.xz" file.. and now here we are. I haven't learned CLJS but at least I got my feet wet with bb 😋
And then just place the .clj script on the path
I started with that but my emacs setup was throwing a hissy fit when trying to auto format the buffer
@robertfrederickwarner If you are in clojure mode it should deal well with the shebang
I may be making some basic mistake in how I'm interacting with the code. Currently, I'm running cider-jack-in-clj
to connect my repl, and then cider-format-buffer
. That results in an Invalid symbol: !/usr/bin/env.
error
Have you put the hash sign in front of this?
yup.
Ah. I wonder if this is just starting up a regular clojure REPL. I'm guessing I'd want this to fire up a babashka repl instead?
Then that could be a bug in cider-format-buffer. I'm always just using this function:
(defun iwb ()
"Indent whole buffer."
(interactive)
(delete-trailing-whitespace)
(indent-region (point-min) (point-max) nil)
(untabify (point-min) (point-max)))
Might be worth filing this bug to CIDERYeah, that will start a regular clojure JVM
I've got to go now, later 💤
Thanks for the tips! Good night
#!/bin/bash
export PATH="/home1/<username>/bin/:$PATH"
export CLJ_BB_LIB_PATH="/home1/<username>/lib/"
exec env bb -cp src "$@"
Making that my bbenv wrapper which I could reference from the parent dir or create a sibling symlink to. Should do the trick to keep host specific things out of the repos.