This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-04-05
Channels
- # announcements (3)
- # babashka (135)
- # beginners (82)
- # calva (55)
- # chlorine-clover (23)
- # cider (13)
- # clara (1)
- # clj-kondo (39)
- # cljs-dev (1)
- # cljsrn (2)
- # clojure (96)
- # clojure-france (3)
- # clojure-uk (24)
- # clojuredesign-podcast (1)
- # clojurescript (56)
- # conjure (73)
- # core-typed (1)
- # cursive (1)
- # datomic (10)
- # fulcro (57)
- # joker (4)
- # juxt (1)
- # malli (20)
- # meander (2)
- # off-topic (54)
- # re-frame (4)
- # reagent (3)
- # shadow-cljs (11)
- # spacemacs (6)
- # sql (26)
- # tools-deps (7)
I know Babashka aliases some namespaces by default (for example, clojure.string
as str
).
Do you think it makes sense to add these default aliases on (clojure.core/ns-aliases *ns*)
?
Speaking of namespaces, is there any way in sci
to give people access to the functions in js/Math
? I am guessing not, because this is a very special case Clojurescript bridge thing.
@mauricio.szabo these aliases only exist in the user namespace, mostly to support oneliners
Really? Because I was running on a specific namespace, without an explicit import. Let me check here if I made some mistake...
@deep-symmetry Sometimes adding a JS class as a namespace works, but that’s kind of hacky. Jeroen was working on some improvements there, maybe you could take a look at his sci PRs
Ah, interesting, those PRs introduced me to the :classes
option that is not in the doc string for eval-string
. But maybe by using that I could provide access to js/Math
. I will give it a try. Thanks!
It works, w00t! 🎉
I’m not sure what you mean. I just added :classes {’Math js/Math}
to my eval-string
opts.
Well, I don’t yet, but I make it available to people drawing diagrams, and as an example in my documentation, (Math/pow 2 8)
returns 128.
(I did try drawing a two-byte cell with the result of that computation, and it showed up correctly as 0100
.)
Here are some tests that also uses this: https://github.com/borkdude/sci/blob/master/test/sci/interop_test.cljc#L52-L62
How possible to get java.util.Calendar
in? My solution for the Meetup task on Exercism calls for it! 😃
@pez Take a look here at the pst.clj
example: https://github.com/borkdude/babashka/#examples
Hmmm, I could switch to LocalDate very easily. Thanks for that! However, babashka does not want to compile (LocalDate/of 2020 4 16)
. It works if I use the fully qualified name, but then clj-kondo complains about LocalDate
being imported, but not used. (I'll go read the README more closely now.)
But I might have found a bug in the nREPL load-file
op. It does not complain about anything being wrong in the file, even though it is not compiling it.
@pez?
$ bb "(import '[java.time LocalDate]) (LocalDate/of 2020 2 20)"
#object[java.time.LocalDate 0x4a625c7c "2020-02-20"]
about load-file, feel free to post an issue (and if you want, optionally of course a PR)
So if I shrink my failing case down, I get
(ns lab
(:import java.time.LocalDate))
(.. (LocalDate/of 2020 4 16) (plusDays 1))
load-file
gives:
Evaluating file: lab.clj
=> #object[java.time.LocalDate 0x4944cca3 "2020-04-16"]
I think it just returns that object because it gets the LocalDate singleton? I'm not very sure.
But trying it like borkdude suggested might get you the result you want.
(ns foo (:import [java.time LocalDate]))
(LocalDate/of 2020 2 20)
The object is what I expect. It is the thing happening in the sceenshot that is the problem.
@pez sorry my bad. This is invalid though:
(ns foo (:import [java.time.LocalDate]))
(LocalDate/of 2020 2 20)
so using a single symbol in import isn't what bb understands apparently. issue welcome
(ns foo (:import [java.time.LocalDate])) ;; invalid syntax in JVM Clojure
(ns foo (:import [java.time LocalDate])) ;; valid syntax
(ns foo (:import java.time.LocalDate)) ;; valid syntax, but not supported by bb / sci apparently
But it still has the same problem as with the bare symbol. nrepl load-file
works, resulting in the object. But nrepl eval
fails.
Created issue: https://github.com/borkdude/babashka/issues/331
@pez Are you 100% sure that the syntax you've used in that issue is the same one as you used in Calva? When I load-file this with CIDER it works correctly
oh btw I was wrong earlier, bb also supports this:
(ns lab (:import java.time.LocalDate))
(LocalDate/of 2020 4 16)
;; Monroe nREPL 0.4.0
user=> (ns lab (:import [java.time LocalDate]))
nil
user=> (LocalDate/of 2020 4 16)
clojure.lang.ExceptionInfo: Could not resolve symbol: LocalDate/of [at line 1, column 2]
user=>
also I don't see an "ns" in sogaiu's dump: "Received" {:id "2", :op :eval, :session "8e35c0a0-039b-41d5-9166-3a15dc081ca1", :code "(LocalDate/of 2020 4 16)"}
not sure what you meant, but line 10 of the paste had:
"Received" {:id "1", :op :eval, :session "8e35c0a0-039b-41d5-9166-3a15dc081ca1", :code "(ns lab (:import [java.time LocalDate]))"}
CIDER implements load-file with sending a message with "op" "load-file" "file" "contents of the entire file"
(import '[java.time LocalDate])
nil
user=> (LocalDate/of 2020 4 16)
#object[java.time.LocalDate 0x6bcd0f2a "2020-04-16"]
user=>
If I make Calva send the ns along, things start to work. I added that info to the issue now.
it's interesting that when i use monroe in a different context, it seems to work -- just not with babashka
Since we know of many clients that do not send the ns
along, maybe that is not required. What say @bozhidar?
This will work well in REPLs, but not in source files, as normally you’d want to evaluate code in the right context.
Ops, that’s a question for load-file
. There I think it doesn’t matter much (especially if the file has a ns
).
(let [explicit-ns (and ns (-> ns symbol find-ns))
original-ns (@session #'*ns*)
maybe-restore-original-ns (if explicit-ns
#(assoc % #'*ns* original-ns)
identity)]
(if (and ns (not explicit-ns))
(t/send transport (response-for msg {:status #{:error :namespace-not-found :done}
:ns ns}))
(let [ctxcl (.getContextClassLoader (Thread/currentThread))
except that babashka creates the not-found namespace instead of sending :namespace-not-found
I’m off the school of thought that believes explicit is better than implicit. 🙂 Still, probably the practical implications of the different approaches are small.
@mauricio.szabo convinced me to create the ns because that is what Clojure itself also does when you type (in-ns 'foo)
Is there a way to capture and display the output of the sh
function?
@pez Thanks for following up. I think "ns"
might be optional, I'll implement a fallback, but it might be good to include anyway
@borkdude thanks I was not using the correct sh
Clojure.java.shell?
Hmm... what if the shell command has side effect to print? For example I use multiple shell command for my compilation and I don’t see the print output of the intermediary commands
@neo2551 For this it's better to use ProcessBuilder
directly: https://github.com/borkdude/babashka/issues/299
the relevant line you're looking for is (.redirectOutput ProcessBuilder$Redirect/INHERIT)
Thanks!
just added babashka support to our http://docopt.org Clojure fork: https://github.com/nubank/docopt.clj#babashka 🙂
@clojurians884 cool! I'll add it to the list of known working libraries 🙂
@borkdude nice! thanks for babashka!
@sogaiu @pez @mauricio.szabo I pushed fixes for the problems with the "ns"
value in nREPL messages to master. It's now optional (so it should work with monroe again) and if the value contains a namespace that doesn't exit yet, it will be created.
if this isn't in the nrepl docs at http://nrepl.org, may be it would be good to suggest as a potential change to @bozhidar?