This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-08-14
Channels
- # aleph (1)
- # announcements (1)
- # beginners (59)
- # boot (2)
- # calva (5)
- # cider (8)
- # clj-kondo (6)
- # cljdoc (5)
- # cljsrn (11)
- # clojure (123)
- # clojure-dusseldorf (1)
- # clojure-europe (4)
- # clojure-italy (22)
- # clojure-losangeles (4)
- # clojure-nl (10)
- # clojure-spec (18)
- # clojure-uk (22)
- # clojurescript (103)
- # cursive (32)
- # data-science (1)
- # datomic (21)
- # events (2)
- # figwheel (1)
- # fulcro (12)
- # graalvm (3)
- # graphql (8)
- # jobs (2)
- # kaocha (4)
- # klipse (2)
- # lein-figwheel (4)
- # leiningen (23)
- # off-topic (11)
- # planck (11)
- # re-frame (8)
- # reagent (2)
- # reitit (3)
- # rewrite-clj (1)
- # ring (1)
- # ring-swagger (31)
- # schema (2)
- # shadow-cljs (66)
- # spacemacs (3)
- # specter (16)
- # sql (9)
- # tools-deps (16)
- # vim (26)
with lein profiles/injections, is it possible to ensure that clojure.repl
is require/use'd in every name space during interactive development? like, the equivalent of a global require? So that (doc doc)
would work no matter which ns I change into as I develop?
In short, no
In long, there are various plugins in various tools that try to do some version of this but they’re all kinda meh
thanks - I like reading it right in the repl as opposed to an editor interface (like cider/emacs buffer for doc) or on a website, but I guess I'll make due
from all ns'es you can do (clojure.repl/doc foo)
I actually use Cursive and instead use the key command to open the doc typically, but sometimes use the fq form if I'm not in user
I have a fn #(set [% id])
which returns a set. It first creates a vector and then converts it into a set. Is it possible to this in one step like what the vector
fn does.
@murtaza52 #(hash-set % id)
(let [ary (int-array 2 2)]
(aset ary 0 1 3)
(aset ary 1 0 4)
ary)
Why does this throw an error saying that ary
is not an array?
Execution error (IllegalArgumentException) at java.lang.reflect.Array/set (Array.java:-2).
Argument is not an array
(let [ary (make-array Integer 2 2)]
(aset ary 0 1 (int 3))
(aset ary 1 0 (int 4))
ary)
this works as expectedHello! Is there a predicate that is true only for vector, list, and set but not a map? Thanks!
Correct but not desriable solution. This is true also for 123 and :hello 🙂
Does it have to be a single predicate? You could just combine them #(or (vector? %) (set? %) (list? %))
I could of course. But a single predicate would be nicer. Otherwise I'd do (and (coll? %) (not (map? %)))
Or perhaps something like this ((every-pred coll? (complement map?)) coll-under-test)
#(and (instance? clojure.lang.IPersistentCollection %) (not (instance? clojure.lang.IPersistentMap %)))
I believe using Clojure's built-in predicates is better than comparing with interfaces (which is, in a way, an impl. detail)
For MacOS, is installing Clojure via homebrew, and then Boot, a good way to get up and going?
have a look at #plum, it intends to be user-friendly tool for getting started. But it targets clj
/ #tools-deps , not Boot.
shadow-cljs is very easy to get going and works very well with the npm ecosystem. I can highly recommend it for all ClojureScript development.
I see shadow-cljs often recommended if you're planning to use a lot of npm packages with clojurescript. Otherwise, tools.deps is pretty popular nowadays, although most older projects you find will be using leiningen. (this also applies to clojurescripts)
I'd recommend going for tools.deps like holyjak says, for both clojure and clojurescript, to get up and started [=
Does someone in Clojurescript typically have some kind of dev process where they also code a backend in Clojure?
if they want a backend, they'll usually include the clojure code in the same project as well, yes. (sharing code between the backend and frontend is very easy with .cljc files) I highly doubt shadow-cljs can do it, but you could ask in #shadow-cljs if you want to be sure. (the rest, ie. boot, leiningen and tools.deps can however)
I heard that shadow-cljs can be used through leiningen. I ran them seperately until now.
@U0522TWDA can you post a link to plum, googled it but cant find anything on it.
@murtaza52 just ask in #plum 🙂
Is there like a major blog post that people refer to for setting up their Clojure development environment?
@slack1899 https://corfield.org/blog/2018/04/18/all-the-paths/ - this gives some history / overview on clojure build tools
@slack1899 this can also be helpful - https://github.com/clojure/tools.deps.alpha/wiki/Tools#versioning-and-releasing - listing of different tools which build on tools.deps
I guess this can never happen in Clojure? just want to make sure:
(let [%x 1] #(+ %x 1))
what I want to make sure: if a symbol in a fn literal starts with percent, it's not something from the outer scope
@danielsz’s article about Lisp, following Heart of Clojure, is now #1 at Hacker News: https://news.ycombinator.com/item?id=20696931 .
@borkdude nobody sane would do it, but it's legal
@noisesmith not sure, because I can't get it to work in both CLJS and CLJ
it happens to be legal in the reader phase, so users using weird tagged readers could be using those, IIUC
oh wow, I thought it would be legal, but testing it I guess it's not
how does clojure
decide what are the command line args to a script?
clj -e '(println *command-line-args*)' 1 2 3
(2 3)
Execution error (FileNotFoundException) at java.io.FileInputStream/open0 (FileInputStream.java:-2).
1 (No such file or directory)
I believe the command-line-args only apply to main classes
here clojure.main is taking two commands -e and an expression and the last args are being interpreted as a script to run (1) and the args to it (2 3)
so this isn't a valid command, which is making it kind of weird
$ clj -e '(println *command-line-args*)' - 1 2 3 </dev/null
(1 2 3)
that asks it to read from STDIN, then sends EOF on STDIN
alternate, golfed
$ echo '(println *command-line-args*)' | clj - 1 2 3
(1 2 3)
when implementing ISeq on a deftype, is it required to also place the ISequential marker protocol on the deftype?
what is ISequential? if it exists it isn't in clojure.lang
I usually don't mess with deftypes but just now I was messing around and had a type that fully satisfied clojure.lang.ISeq, yet would complain that nth
was not supported on the type
oh yeah, Sequential comes in via this codepath https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/RT.java#L900
i somewhat instinctually looked for protocols that may be associated with that method, found Indexed and Sequential, figured Indexed didn't make sense for my case and just shoved Sequential in there and all my problems went away.
hmm, even if you have Seqable I guess
One more question ... when defining a function that shadows an existing protocol method in the same namespace, I was surprised that the protocol version still was visible. I assumed that latter defn
would clobber the protocol version and this wouldn't work for example:
So it appears that the polymorphic version is still in the namespace, despite that I've defined over it. How does that work? Does the call to (some-thing 10 thing)
somehow know there is an existing polymorphic version and check the types there first before dispatching on the "catch-all" (unimplemented) version or something? I wouldn't think so because for fallthrough implementations you have to explicitly implement them on Object.
but it actually doesn't outright shadow it, because the body of the same function correctly dispatches on the first argument (the protocol version is called)
or maybe a better description is that it shadows it, but somehow the protocol version is still available in the namespace when called with the appropriate arguments
protocol functions have some metadata attached which the compiler uses to guide how they are compiled and re-defing doesn't clear that metadata
i was going to say... it's as if every single call to some-thing
is dispatching on it's type, whether or not implemented as a protcol method
like somehow the subsequent global def is being added to the protocol table as a catchall or something
I would probably make the protocol version -some-thing
to avoid any confusion, but I was surprised nonetheless that the shadowed version was available
it is a weird compiler bug and you shouldn't use it as a feature or try to explain how it is working, which is what @ghadi was getting at by calling it undefined behavior
if you create a protocol function then def it as a normal function, assume the compiler is going to output code that will zero out your hard drive
yah, i know the standard behavior is to prefix the protocol method with "-" and wrap that if needed
I was more curious when I accidentally wrote the code how it was working, not planning on using it for real stuff
why even use the same name in the same namespace?
again, i would just do (defn some-thing [x this] (-some-thing this x))
if i needed this
Just trying to correct my mental model of how protocol definition/dispatch works, which was obviously not quite right when i stumbled on this
FWIW @creditobrasil the call (some-thing 10 thing)
in your example causes a stack overflow in ClojureScript
Even then, ClojureScript is a bit tricky (and I think so is Clojure) because the compiler can see and optimize a "self call"
i'll just stick with @hiredman's recommendation and assume any use of the shadowed version as presented will rm -rf my drive
and calling it undefined behavior is kind of stretch too because that assumes a definition where it is left out so as to be undefined
so if you call it a bug in the compiler that is hard to fix or undefined behavior to some degree depends on how close you orbit to rhickey
there's an extra "Please see" in the middle, yeah
happens with if too
I was curious about whether it is specified that the init in a def
can refer to the name being defined.
you can see it if you squint and read between the lines (the fact that it creates the binding, and then evaluates init, implies that the init can use the binding)