Is there a recommended way to provide auto-completion in inf-clojure
, when using babashka?
I see the default config currently doesn't define the completion
feature:
https://github.com/clojure-emacs/inf-clojure/blob/master/inf-clojure.el#L131-L141
but after seeing https://www.youtube.com/watch?v=TvBmtGS0KJE i have the suspicion that nowdays it's possible to do define it in some reasonable way, even if it involves pulling in the clj-kondo pod.
Having malli to be bb compatible would be very nice, imho. Even a subset of that, which allows for validation and value transformations. I could see that very useful for command line validation or API validation.
@ikitommi @steveb8n I have a feature-malli
branch pushed to babashka repo.
$ ./bb -e "(require '[malli.core :as m]) (m/validate [:and int? [:> 6]] 7)"
true
$ ./bb -e "(require (quote [malli.core :as m])) (m/validate [:and [:fn '(fn [x] (int? x))] [:> 6]] 7)"
true
@ikitommi It seems the borkdude.dynaload setting really helps, it shaves almost 40mb of the binary size
You can try the binary from the #babashka-circleci-builds channel :)
I guess if malli would end up in bb, then we would need some kind of cli-matic like library which is not based on spec, but on malli ;)
Dear bb community. Consider leaving feedback in this issue about adding malli: https://github.com/babashka/babashka/issues/737
$ ./bb -e "(malli.error/humanize (malli.core/explain [:map [:x string?] [:y int?]] {}))"
{:x ["missing required key"], :y ["missing required key"]}
wooot. PR coming? ;)
(ns foo
(:require [clojure.tools.cli :as cli]
[malli.core :as m]
[malli.transform :as mt]))
(def cli-options
[["-n" "--number NUM" "A number"
:parse-fn (m/decoder int? mt/string-transformer)
:validate [(m/validator [:< 100])]]])
(prn (cli/parse-opts ["-n" "99"] cli-options))
;; =>
;; {:options {:number 99}, :arguments [], :summary " -n, --number NUM A number", :errors nil}
(prn (cli/parse-opts ["-n" "100"] cli-options))
;; =>
;; {:options {}, :arguments [], :summary " -n, --number NUM A number", :errors ["Failed to validate \"-n 100\""]}
This doesn't require a PR
@ikitommi Is it possible to get the humanized error for [:< 100]
? tools.cli expects a hard-coded string that is not dependent on the input :/
if this was a function, then we could plug in humanize there
maybe they will accept a PR
I will ask. This would also helpful for clojure.spec
@ikitommi To clarify: If a lib works in Clojure and with GraalVM, it will also work with bb if it's included as a built-in library. But it's another story when you try to run this lib from source with bb itself
does babaksha supports transients? got bitten by missing dissoc!
:
wilkerlucio@Wilkers-MacBook-Pro-2 babashka-experiments % bb <http://pathom.bb|pathom.bb>
----- Error --------------------------------------------------------------------
Type: clojure.lang.ExceptionInfo
Message: Could not resolve symbol: dissoc!
Location: com/fulcrologic/guardrails/utils.cljc:85:89
Phase: analysis
----- Context ------------------------------------------------------------------
81:
82: (defn map-vals [f m] (if (nil? m) {} (reduce-kv (fn [m k v] (assoc m k (f v))) m m)))
83: (defn map-keys [f m] (if (nil? m) {} (reduce-kv (fn [m k v] (assoc m (f k) v)) {} m)))
84: (let [p! persistent!, t transient] ; Note `mapv`-like nil->{} semantics
85: (defn filter-vals [pred m] (if (nil? m) {} (p! (reduce-kv (fn [m k v] (if (pred v) m (dissoc! m k))) (t m) m)))))
^--- Could not resolve symbol: dissoc!
it should, but it could be missing :/
@wilkerlucio It should be added here: https://github.com/borkdude/sci/blob/043f5e60d674f5aeee0866e427cef58812ad5547/src/sci/impl/namespaces.cljc#L877
you pointed to dissoc
, the missing one is dissoc!
(with exclamation mark)
yes, that one is missing, but should be added there
ah, ok, so a simple add there will fix it?
yes
I can send a PR for that if you want
please :)
I'm excited to maybe see Pathom running inside Babashka, that will be awesome 😄
was just trying that spartan spec hack to get though spec (that was the blocker)
why does pathom need spec?
macros, I use the spec regex to parse custom macro syntax
Merged, and I pushed the new sci to bb master. Binary will appear in #babashka-circleci-builds soon
awesome! 🎉
is there a proper way to make this portable with Babashka?
wilkerlucio@Wilkers-MacBook-Pro-2 babashka-experiments % ~/Local\ Files/bb <http://pathom.bb|pathom.bb>
----- Error --------------------------------------------------------------------
Type: clojure.lang.ExceptionInfo
Message: Could not resolve symbol: clojure.lang.Atom
Location: com/fulcrologic/guardrails/utils.cljc:88:31
Phase: analysis
----- Context ------------------------------------------------------------------
84: (let [p! persistent!, t transient] ; Note `mapv`-like nil->{} semantics
85: (defn filter-vals [pred m] (if (nil? m) {} (p! (reduce-kv (fn [m k v] (if (pred v) m (dissoc! m k))) (t m) m)))))
86:
87: #?(:clj
88: (defn atom? [x] (instance? clojure.lang.Atom x))
^--- Could not resolve symbol: clojure.lang.Atom
89: :cljs
90: (defn ^boolean atom? [x] (instance? Atom x)))
@wilkerlucio I think clojure.lang.IAtom
works
$ bb -e '(instance? clojure.lang.IAtom (atom nil))'
true
this seems to say true for everything:
wilkerlucio@Wilkers-MacBook-Pro-2 babashka-experiments % ~/Local\ Files/bb -e "(satisfies? clojure.lang.IAtom {})"
true
wilkerlucio@Wilkers-MacBook-Pro-2 babashka-experiments % ~/Local\ Files/bb -e "(instance? clojure.lang.IAtom {})"
true
wilkerlucio@Wilkers-MacBook-Pro-2 babashka-experiments % ~/Local\ Files/bb -e "(instance? clojure.lang.IAtom (atom {}))"
true
wilkerlucio@Wilkers-MacBook-Pro-2 babashka-experiments % ~/Local\ Files/bb -e "(satisfies? clojure.lang.IAtom (atom {}))"
true
omg..
This is probably a bug
I will file an issue
For now you can use this workaround:
$ bb -e '(= "clojure.lang.Atom" (.getName (class (atom nil))))'
true
Note that you can use reader conditionals, :bb
should go before :clj
gotcha, thanks, about making (instance? clojure.lang.Atom x)
works, its out of scope for babashka?
I found interesting that the class type is correct, but I dont understand why the instance check doesn't work
(or why it can't find a class by name, but can by inspecting the atom)
@wilkerlucio This has to do with how sci works. You have to explicitly add classes by name in order for them to get resolved.
But IAtom
is basically a hack to make it work with defrecord
and defprotocol
and this is probably related to the instance?
bug, I'll check
I see. In bb/sci IAtom is implemented as a protocol and this protocol has a default dispatch and this is why satisfies? returns true for all object. This is the root cause of this bug.
This needs a deeper look. Sorry for the inconvenience here.
no worries, just experimenting at this point, no impact 😉
The root cause is that IAtom is implemented using multimethods under the hood and we have a default, so basically everything returns true for this particular hack ;)
This was done so people could reify IAtom
I am trying to implement this now without a default multimethod, but this doesn't work in CLJS :/
@wilkerlucio The bug should be fixed on master now
you are awesome man! 🎉
I am awaiting your next issue :)
damn, you are a fast worker. being locked inside by winter must be good for productivity 🙂
The weather is getting better now...
This might be a little niche, but I just released a pod that can format T-SQL using the vendor library (on .NET): https://github.com/xledger/pod_tsql_scriptdom
I love niche projects!
@isak Are you aware that there is now also a native mssql pod? You can talk directly to mssql from a pod, from the pod registry
I haven't tested it myself, since I don't have a ms sql db to connect to
This one? https://github.com/xledger/pod_sql_server yea I use it for scripting
@isak no this one:
(require '[babashka.pods :as pods])
(pods/load-pod 'org.babashka/mssql "0.0.1")
https://github.com/babashka/babashka-sql-pods/this one doesn't need a .NET install and downloads automatically
some testing would be nice
oh sweet, I'll give it a shot. Usually the problem is integrated security, but maybe they figured it out.
ah hm, not sure. @jvtrigueros is the guy who did the work on that, he might know
I guess it's not much different from connecting from a regular Clojure program via JDBC
For normal JDBC, it is a little tedious, because you need a special dll for that to work, and it doesn't seem to come packaged properly with the rest of the driver deps
Right.
I think it would be good to add a link to your pod in section with related sql pods. Feel free to PR with some details (I don't know enough about mssql)
You can also add a link to your sql formatting pod
Hmm, I'm getting this error:
Type: java.lang.IllegalArgumentException
Message: No executable found for pod org.babashka/mssql (0.0.2) and OS Windows Server 2016/x86_64
from this:
(require '[babashka.pods :as pods])
(pods/load-pod 'org.babashka/mssql "0.0.2")
Sorry I didn't try on Windows!
aah that's right, sorry about that. There is no Windows version (yet)
You could try from WSL(2) perhaps, some time. No worries.
Ok just tested it. Unfortunately I get this error when adding :integratedSecurity true
to the db spec:
----- Error --------------------------------------------------------------------
Type: clojure.lang.ExceptionInfo
Message: This driver is not configured for integrated authentication. ClientConnectionId:889ad681-4fdf-409c-b12c-9eef93129023
Nice, another thing to add to the troubleshooting section then. Along with a link to your pod
Thanks a lot for trying
np