This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-11-28
Channels
- # announcements (1)
- # babashka (9)
- # beginners (82)
- # calva (6)
- # cider (3)
- # clj-kondo (69)
- # cljdoc (4)
- # cljs-dev (10)
- # cljsrn (2)
- # clojure (74)
- # clojure-europe (11)
- # clojure-italy (9)
- # clojure-nl (15)
- # clojure-spec (18)
- # clojure-uk (89)
- # code-reviews (8)
- # core-async (42)
- # cursive (22)
- # datomic (26)
- # fulcro (13)
- # graalvm (31)
- # graphql (1)
- # leiningen (20)
- # malli (19)
- # music (1)
- # off-topic (4)
- # pathom (56)
- # re-frame (3)
- # reitit (26)
- # shadow-cljs (40)
- # spacemacs (5)
- # tools-deps (25)
i'm defining a new client/server protocol in which the client sends EDN to the server in the shape of ... {:kind :tx :data {:name :foo/bar :args [13 "baz" :fizz]}}
basically i want to "route" the request based on the :kind
and :name
would using a multimethod seem like an obvious choice for this?
iirc defmulti can handle one pattern at a time so you'd have to write it separately for kind
and name
defmulti
takes a function in parameter, you can write (fn [x] [(:kind x) (get-in x [:data :name])
in defmulti and match it with e.g. (defmethod foo [:tx :foo/bar] ...)
Any way of setting *warn-on-reflection*
true only for our own files? I'm flooded with warnings from dependencies
You can put (set! **warn-on-reflection** true)
in individual source files.
Right now it's set through lein's :global-vars
, I was hoping there was a way to set it on, say, all ./src
files
Although when you set it on a source file, it stills applies to every other source file right? As it's a global var. So maybe setting it in the entry point of my app instead of in lein's global-vars does what I want
It is bound in each file, not globally, in my experience, when you use that expression in a source file.
If a source file does something like load-file
on other source files (which is pretty uncommon from Clojure projects I have seen), then I think it propagates through to the files being loaded, but it does not propagate to other namespaces that a namespace requires, for example.
I mean, try it and see.
you're correct, I had tested in a repl before and it seemed to propagate, but it actually seems source-file bound
what's the right incantation to make (s/def (f "foo") any?)
work? spec complains that k must be fully qualified keyword so i'm trying to make a macro that returns essentially ::foo
but no luck so far
something like this works though:
(defmacro nsdef [k spec]
`(s/def ~(keyword namespace-name (cond-> k keyword? name string? identity))
~spec))
Hi, people. I need UI component I can use in my browser which allows to edit clojure code (does some syntax highlight, bracketing, idention) and thats all In general from REPL I neeed R part... as E part will be handled by clojure on the server
Well, the nice thing there is that functionally you're reading a string from a field and passing it to a server-side REPL. You can use the interface from this if you wanted something ready made, though implementing paren-matching/function highligting would be good for practice. https://github.com/oakes/Nightlight
But NIghtLight is full fledged IDE, I just want some sort of I dont know simple "TextArea" sort of tag or something I can drop into the page.... I doubt I can integrate whole nightlight in a simple web browser app
<title contenteditable>Hello World</title>
<style contenteditable>head, title, style {display: block;}</style>
You'll want to set the font-family:
and white-space:
properties for it to monospace and pre to get the font and preserve line breaks.
You have Klipse https://github.com/viebel/klipse There are Clj/Cljs demo on this page : https://book.klipse.tech/
Do we have any editors yet that can do this: https://www.youtube.com/watch?v=d8-b6QEN-rk ?
Hi peepz, I am trying to install tailwindcss webjar, but lein deps
fails with
Could not find metadata org.webjars.npm:caniuse-lite/maven-metadata.xml in local (/home/naiali/.m2/repository)
Failure to find org.webjars.npm:caniuse-lite/maven-metadata.xml in was cached in the local repository, resolution will not be reattempted until the update interval of clojars has elapsed or updates are forced
Could not find metadata org.webjars.npm:caniuse-lite/maven-metadata.xml in local (/home/naiali/.m2/repository)
I removed .m2 and tried again, no joy 😅 complete n00b here, so I am completely stuckI don’t know tailwindcss webjars, but there is a library to work with tailwind from clojure - https://github.com/mrmcc3/tailwind-clj
is zipmap
expected to keep the order of keys in the map generated to be same as the keys coll arg ?
thanks , just noticed that it is ordered to keys arg for colls of size 8 or less , anything larger the result is unordered
(type {1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8})
;; => clojure.lang.PersistentArrayMap
(type {1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9})
;; => clojure.lang.PersistentHashMap
Interestingly, the explicit hash-map constructor with 0 args returns the wrong type
(type (hash-map))
;; => clojure.lang.PersistentArrayMap
Hash maps with small numbers of elements (including zero elements) are implemented as array maps. Not a bug.
user=> (type {:a 1 :b 2 :c 3 :d 4 :e 5 :f 6 :g 7 :h 8})
clojure.lang.PersistentArrayMap
user=> (type {:a 1 :b 2 :c 3 :d 4 :e 5 :f 6 :g 7 :h 8 :i 9})
clojure.lang.PersistentHashMap
user=>
The change is at the 8/9 element boundary @qythium /cc @zyxmndaleyjesI've added an example to zipmap just in case someone else mistakes it to be ordered like I did
Yeah, it's tempting when tutorials use small hash maps and they seem to maintain order.
There are also things like these: https://github.com/clj-commons/ordered
I would avoid such things, personally, because it has the potential to be very confusing: built-in hash maps and sets being unordered, mixed with code that expects "special" hash maps and sets to be ordered. To say nothing of the issue of predictable performance on lookup/traversal...
I am pretty sure that at least some of the third party ordered set/map implementations have good performance guarantees.
As you warn about, though, all it takes is one call to some function like merge
or similar, with a non-ordered map in the "wrong" position, to return an unordered map again.
Yep, I understand the whole implementation/interchangeability thing, but I would think the hash-map
and array-map
functions were supposed to explicitly return those respective types
from the source code:
(defn hash-map
"keyval => key val
Returns a new hash map with supplied mappings. If any keys are
equal, they are handled as if by repeated uses of assoc."
{:added "1.0"
:static true}
([] {})
([& keyvals]
(. clojure.lang.PersistentHashMap (create keyvals))))
Ah, I'd missed the subtlety of that... I guess now I'm more surprised that (hash-map :a 1)
does not produce an array map! 🙂
also, (self-hosted) clojurescript has the "correct" behaviour:
$ lumo
ClojureScript 1.10.520
cljs.user=> (type (hash-map))
cljs.core/PersistentHashMap
It does seem a bit surprising, perhaps, that hash-map
can return an object of type PersistentArrayMap, but yeah, if you try writing code that treats the concrete type of map returned by a function as an implementation detail, with no ordering guarantees (unless it is one of the ordered map types that explicitly guarantee ordering), then you will be happier long term.
I’m pretty new to Clojure and I am wondering about declaring variables in the leiningen project.clj file. I want to implement some gRPC services and the dependencies look like this:
[io.grpc/grpc-core "1.13.1"]
[io.grpc/grpc-netty "1.13.1"]
[io.grpc/grpc-protobuf "1.13.1"]
[io.grpc/grpc-stub "1.13.1"]
Is there any way I could declare the version string there in a variable to avoid some writing?@gbson You can but it relies on a "quirk" of Leiningen and you wouldn't be able to do that if you switched to CLI/`deps.edn` at some future date.
You could put (def grpc-version "1.13.1")
above the defproject
form in project.clj
and then use ~grpc-version
in the dependency vector to get the version value substituted as I recall (been a long time since I've used Leiningen!).
I’m only building a really simple application now to move some data around, to get familiar with the language
Leiningen is a "classic" and most tutorials/books still use it but more and more people are using the "official" CLI (`clj` / clojure
scripts) with deps.edn
.
Are you on Windows or macOS/Linux?
'k, so you can brew install clojure
to get the new CLI tools.
(assuming you already have Homebrew on your Mac!)
Git and local deps, yeah. Lots of nice stuff with the new tooling.
Check out https://github.com/seancorfield/dot-clojure as a guide for what you can do with your ~/.clojure/deps.edn
file.
Nice - currently we provide our api stubs as git projects so it may be very easy to use them here then
Clojure 1.10.x works with all JDK versions 8 and later.
Clojure is tested against quite a few JDKs https://build.clojure.org/job/clojure-test-matrix/
There are a few issues with warnings/etc. that you might experience on later JDKs that do not occur with earlier JDKs, but those are mostly because of tightening security restrictions in later JDKs, less because of Clojure. e.g. as described here: https://clojure.org/guides/faq#illegal_access
which you can mostly ignore, and/or handle via techniques described in the answer there, if you care to.
(= (rand-int 2) 0)
should return true or false with equal probability.
You can use rand-int
with a larger range, and whatever condition on the return value you want, if you want non-equal probabilities for true vs. false.
Perfect. Thanks @andy.fingerhut!
Thanks @U0K064KQV! Sorry for the late reply. I had to run to dinner yesterday.