This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-11-22
Channels
- # announcements (2)
- # babashka (64)
- # beginners (41)
- # calva (4)
- # cider (1)
- # clj-kondo (78)
- # cljdoc (31)
- # cljsrn (4)
- # clojars (2)
- # clojure (109)
- # clojure-germany (1)
- # clojure-italy (8)
- # clojure-nl (2)
- # clojure-spec (8)
- # clojure-uk (28)
- # clojurescript (61)
- # code-reviews (2)
- # cryogen (2)
- # cursive (23)
- # datomic (21)
- # duct (15)
- # fulcro (37)
- # graalvm (17)
- # graphql (3)
- # jackdaw (3)
- # joker (11)
- # lein-figwheel (4)
- # malli (42)
- # off-topic (97)
- # pathom (4)
- # pedestal (1)
- # portkey (3)
- # re-frame (7)
- # reagent (13)
- # reitit (2)
- # shadow-cljs (54)
- # spacemacs (1)
This could potentially be fun to port to babashka: https://clojureverse.org/t/uberjar-from-the-shell-for-tools-deps/5113
I'm not sure if I read it correctly, but would porting boot-clj
to babashka be a similar effort?
I think boot-clj has graalvm plans of their own and will be a massive undertaking for babashka, probably not going to try it
But the uberjar script is just a small shell script that could be implemented using babashka, not inside babashka
ok cool, yes at the very minimum a good start indeed
i agree that boot-clj would be a very complex undertaking, but I can see some benefits of something in this direction
yeah, I was thinking about the immutable fileset thing which could be complex, maybe a similar thing like tasks which can be invoked from the command line could be nice
it can already be done right now with functions + clojure.tools.cli though in babashka
yeah exactly I think the functional approach could work nicely. I'm experimenting with a first tool. Let's see how it evolves
maybe a makefile-ish thing in babashka could work. drawing inspiration from mach? https://github.com/juxt/mach it doesn't seem they are actively using it anymore though
Yeah I don't like the npm part, but given it's in clojurescript. would be nice to port to babashka
I just noticed some->
is missing as macro. And then I was thinking can we not re-reuse clojure's macro code somehow e.g. via clojure.repl/source-fn
. I tried something like this
(defn defmacro [mname args]
(let [f (eval `(defn (symbol (str (name mname) "*")) ~@args))]
(macrofy @f)))
(defn extract-macro [supported-macro]
(let [source-fn (fn
[x]
(when-let [v (resolve x)]
(when-let [filepath (:file (meta v))]
(when-let [strm (.getResourceAsStream (RT/baseLoader) filepath)]
(with-open [rdr (LineNumberReader. (InputStreamReader. strm))]
(dotimes [_ (dec (:line (meta v)))] (.readLine rdr))
(let [text (StringBuilder.)
pbr (proxy [PushbackReader] [rdr]
(read [] (let [i (proxy-super read)]
(.append text (char i))
i)))
read-opts (if (.endsWith ^String filepath "cljc") {:read-cond :allow} {})]
(if (= :unknown *read-eval*)
(throw (IllegalStateException. "Unable to read source while *read-eval* is :unknown."))
(read read-opts (PushbackReader. pbr)))
(binding [*read-eval* false]
(read-string (str text)))))))))]
(eval (source-fn supported-macro))))
But this has some issues. @borkdude did you already consider something like this? Maybe I should just stick to copy pasting the code instead š@jeroenvandijk this worked for me:
(defmacro some->
[expr & forms]
(let [g (gensym)
steps (map (fn [step] `(if (nil? ~g) nil (-> ~g ~step)))
forms)]
`(let [~g ~expr
~@(interleave (repeat g) (butlast steps))]
~(if (empty? steps)
g
(last steps)))))
(println (some-> {:a 1} :a))
(println (some-> {:a 1} :a ::c))
cool, yes it seems to work in a test file
I guess my magic approach is a bit too lazy and unnecessary complexity anyway
relevant file + position where it probably should be added: https://github.com/borkdude/sci/blob/8579dcb84934253fb44e88e381052e24224f748e/src/sci/impl/namespaces.cljc#L93
yes, i'll do that. Thank you!
btw, do you want a (simple) test case for this as well?
cool, i'll look into it
I haven't got test cases for all macros, because often it's just a 1-1 copy from clojure core
I've thought a little bit more about adding spec. I made a note in the issue saying that spec relies a lot on namespaces, so that might not fit well currently with babashka and sci, because these don't have namespaces yet
maybe just so it doesn't get removed by accident as sanity check
yeah i was actually thinking about namespaces too. I noticed that I need to do something like this in order to make it work in both clojure and babashka
#?(:clj (ns adgoji.application.cli
))
(require '[clojure.tools.cli :as cli])
maybe it's worth to implement as simple version of the ns macro just to get rid of the reader conditionals like this?yes, but then I might just go all the way, since naming a namespace in the namespace form implies that you can have multiple
true. I don't know how complicated a namespace implementation would be
but since vars and namespaces are not real in sci (because sci doesn't mutate the host environment) I expect this to not work with spec out of the box
sounds plausible. I guess this holds for many libraries
ah that's what you mean
yeah I actually don't use fdef
much. That could be implemented later if someone misses it?
multispec would be complicated as well I guess
That's something I do use a lot
If you ever want to implement multimethods or protocols, you also depend on redefining vars
I'm not sure what my use case would be for protocols in Babashka, but I can imagine it being nice for not having to deal with the reader conditional part
yeah well actually it could magically work out, since you can just do def
in babashka and it will define something in the local environment
Probably something for the christmas break: https://github.com/borkdude/sci/issues/169
btw, I added some->
https://github.com/borkdude/sci/pull/168 but not sure why it doesn't work in babashka locally
yep
ā sci git:(feature/add-some-arrow) lein run "(some-> {:a 1} :a)"
1
ā sci git:(feature/add-some-arrow) lein bb "(some-> {:a 1} :a)"
'bb' is not a task. See 'lein help'.
Did you mean this?
do
ā sci git:(feature/add-some-arrow) cd ..
ā babashka git:(master) ā lein bb "(some-> {:a 1} :a)"
1
ā babashka git:(master) ā
guess that's good?
I tried to compile with script/compile
Not sure, ah well
ok great, not sure. I'm doing too many things at once š