This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-12-02
Channels
- # adventofcode (47)
- # announcements (7)
- # aws (1)
- # babashka (52)
- # beginners (80)
- # boot (3)
- # calva (19)
- # cider (9)
- # cljs-dev (1)
- # clojure (48)
- # clojure-brasil (1)
- # clojure-dev (27)
- # clojure-europe (3)
- # clojure-madison (3)
- # clojure-nl (29)
- # clojure-spec (11)
- # clojure-sweden (1)
- # clojure-uk (49)
- # clojurescript (66)
- # core-async (20)
- # cryogen (4)
- # cursive (13)
- # data-science (7)
- # datomic (5)
- # emacs (30)
- # figwheel-main (11)
- # fulcro (15)
- # graphql (8)
- # jobs (5)
- # joker (17)
- # lambdaisland (1)
- # leiningen (2)
- # malli (2)
- # off-topic (5)
- # pathom (22)
- # re-frame (12)
- # reagent (29)
- # reitit (2)
- # ring (10)
- # shadow-cljs (57)
- # specter (3)
- # tools-deps (22)
- # vim (5)
- # xtdb (7)
@dominicm make a middleware that intercepts eval messages, that's basically what piggieback does
That's a good idea. I think there's good reason to treat it as differently for babashka though, I'm assuming babashka would be a standalone server rather than coexisting with clojure
slightly less trivial than it sounds because nrepl middleware is confusing as heck, but at least in theory fairly straightforward
is there a tutorial on cider / nrepl middleware? this topic also has come up in clj-kondo: maybe it's possible to have a middleware which lints your project and then emits feedback like unused vars.
@borkdude I think that my blog post has a lot of internal detail. But the examples in the source of nrepl are pretty good.
What do you think about the following? in babashka / sci everything that is def'ed is effectively treated as a constant.
it's even a little bit more strict than direct linking in clojure.
so (def ^:const x 1) (defn foo [] x) (def x 2) (foo)
will return 1 in Clojure
but: (def x 1) (defn foo [] x) (def x 2) (foo)
will return 2 in Clojure, but 1 in babashka.
I'm now implementing real vars, so you can opt out of this:
$ bb '(def ^:redef x 10)
(defn foo [] x)
(def x 11)
(foo)'
11
I would consider making this the default behavior (without the ^:redef annotation), but so far nobody has complained / asked about this.also, there will be "real" dynamic vars:
$ bb '(def ^:dynamic *foo* 1) (binding [*foo* 2] (prn *foo*)) *foo*'
2
1
my vote is to make redef default without the annotation -- i think it will be less confusing
yeah, it wasn't a very conscious decision to make it behave like ^:const
, I think it was more driven by the absence of real vars so far
there is a var branch in babashka and sci where I'm developing this, in case you want to try it out. I agree with sogaiu that we should probably be as close to clojure as possible
the CLJS version of sci is even closer to JVM clojure than CLJS is in this respect:
(require '[sci.core :as sci])
(println (sci/eval-string "(def ^:dynamic x) (set! x 10)")) ;; Can't change/establish root binding of #'x with set
hmm, i asked because when i tried in sci, i got:
(print (sci/eval-string "(def ^:dynamic x) (binding [x 2] (set! x 10) (print x))"))
nilnil
but you can bring in the normal in and out by using the {:out *out*}
option, then you will bind the internal *out*
dynamic var to the external *out*
value
or you can just bring in the external print using {:namespaces {'clojure.core {'print print}}}
, these are your options now
this decision is based on not mutating the world when evaluating sci expressions, unless the sci library user gives permission for this
also the :namespaces
approach worked too
sounds like there is some kind of jail functionality
there is also (sci/with-bindings {sci/*in* *in* sci/*out* *out*} (sci/eval-string ...))
The issue is here btw: https://github.com/borkdude/sci/issues/175