This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-06-09
Channels
- # beginners (121)
- # boot (28)
- # cider (106)
- # clara (57)
- # cljs-dev (70)
- # cljsrn (6)
- # clojure (145)
- # clojure-dev (7)
- # clojure-italy (36)
- # clojure-russia (42)
- # clojure-spec (26)
- # clojure-uk (127)
- # clojurescript (103)
- # core-async (10)
- # cursive (56)
- # datascript (66)
- # datomic (16)
- # defnpodcast (1)
- # emacs (18)
- # events (6)
- # figwheel (1)
- # jobs (1)
- # luminus (1)
- # lumo (44)
- # off-topic (58)
- # om (17)
- # onyx (2)
- # parinfer (75)
- # pedestal (4)
- # re-frame (18)
- # ring (4)
- # ring-swagger (8)
- # rum (7)
- # spacemacs (7)
- # specter (2)
- # sql (4)
- # unrepl (39)
- # untangled (17)
- # vim (3)
- # yada (21)
All I can tell from docs is "returns nil when input is not supported or not a collection" and we know it can't be the latter...
it’s just an odd thing that I didn’t expect, not really relevant to your issue at all
I’m sure it has nothing to do with the values in the coll
Yes, to refine that: empty
likely doesn't support MapEntry
. If you think about it, what would it even return for that coll type?
right, except clojure implicitly turns vectors into MapEntry in other contexts, and vector? on a MapEntry returns true iirc
which is the source of my surprise
it’s a key/value pair that happens to be somehow vaguely vectorish but is always exactly 2 elements in length I guess?
:shruggo:
That behavior is occasionally useful, although not enough I don't forget about it, but that explains why vector?
returns true
. I'm just unsure what you mean about implicit conversion the other way. Where would you see that?
it turns vectors into map-entries implicitly, but not other types (eg. lists)
That makes sense to me (lists can't be associative). I'm unsure where you saw it coming up in that test snippet.
that’s a good point about associativity
That such conversion changes the semantics of testing for coll types is a wort, though, if you ask me. I'd rather have to explicitly convert everything and not have to ponder these issues 😛
https://clojurians.slack.com/archives/C03S1KBA2/p1496966626910635
because maps in clojure are Seqable
and when first
is called on the map, it seq
s it. Conceptually it makes sense, as keys and values are joined at the hip. PersistentHashMap
implements seq
this way, so it decides how the world will view it as a seq
-- all part of abstraction
public ISeq seq(){
ISeq s = root != null ? root.nodeSeq() : null;
return hasNull ? new Cons(MapEntry.create(null, nullValue), s) : s;
}
@sophiagoThanks @joshjones. I figured it out intuitively from Justin's next example, but your explanation is more concrete.
let's say you want to for
a map, or loop
over a map -- it's as easy as:
(for [[k v] your-map] ...)
anyway, just showing an example of how it's useful to view the map this wayI know, I've taken advantage of that occasionally. And it's hardly a big deal one way or another. But personally, I would have required an explicit conversion so as to avoid this entire confusion.
Is there a more concise way of writing (let [{:keys [a b c]} (if foo? {:a "foo" :b "bar" :c "baz"} {:a "quux" :b "baaz" :c "gegl"})])
?
@U053XQP4S: Thanks. CPS?
when a function returns many values, instead of wrapping the values in a collection, the function accepts an extra argument which is a multi-arity function that will be called with the values just before returning
Ok, interesting. On first glance it doesn't seem to fit my situation very well, but I will ponder it. Thanks 🙂
I need to connect to Oracle 8.1.7 and newer version (like 11.x) and the drivers come as different jar (classes12.zip and ojdbc6.jar) but the used class is the same: oracle/jdbc/driver/OracleDriver.class => how would you deal with this? Currently, I generate two uberjar... Searching the web, there seems to be no simple solution, maybe playing with class loader, etc...
Clojure support number as prefix for non-namespaced keyword, but not namespaced keyword
clojure
;; user> :1min
:1min
;; user> :period/1min
;; RuntimeException Invalid token: :period/1min clojure.lang.Util.runtimeException (Util.java:221)
user>
nothing in core like (select-keys-by-ns {:foo/bar 1 :foo/baz 2 :foo/stg 3 :meh/1 :meh/2} "foo") -> {:foo/bar 1 :foo/baz 2 :foo/stg 3}
right?
simple enough to do it manually, but I am wondering if this is possible via new destructuring or something else
well, I don't really care about perf here, I ll just do a reduce-kv based helper and be done with it (no specter on this project)
Just discovered a way to print intermediate results inside arrow macros for debugging purposes:
(-> v transform)
;; with spy:
(-> v (doto prn) transform)
But what about thread-last?
(->> xs transform)
;; with spy:
(->> xs (#(doto % prn)) transform)
Essentially, this works like http://clojure.github.io/tools.logging/#clojure.tools.logging/spy but is universally available and doesn't require an extra dependency.I (or actually my manager wonders) how many active clojure developers are there today?
The State of Clojure survey might give an idea, but it only takes into account the people that actually took the time to answer it
The first figure I think is what you are asking for
There are almost 10K people in this Slack, so I suspect there are actually more people doing Clojure than the survey surfaces
@bherrmann based on a number of sources of data, I would confidently say it’s between 20k and 50k
it matters a lot what you mean by “active”
@alexmiller Thanks... I think my managers policy is to prefer technolgies where there is sufficent quantities of people working in the space. I presume his definition is "mostly working every workday primarily in X" ... but there is already so much fuzziness here...
Yeah, what Alex said. I love Clojure and used it actively for several years, but my current job doesn't give me the opportunity. I'm still a Clojurian at heart, but I don't use it very often these days.
I consider myself very lucky to have entered my current employer as a CFML developer (effectively) and been able to steer them to Clojure, and now we have a dedicated (but small) Clojure back end team and all new back end work is done in Clojure. We’ve replaced several “legacy” CFML apps (that were built after I joined) with Ring/Compojure apps already and hope to replace the largest remaining CFML app this year.
How do you do "Hot Code" reloading with Clojure (clj). Figwheel seems to be (cljs) only?
@hiredman So what if I want to use and editor, and have it recompile/execute on save?
Yeah, if you use Cursive you'll get pretty intuitive REPL-loading that's better than recompile on save
Plus of course there's emacs and its historically great LISP support, and Vim has a surprisingly active Clojure ecosystem as well
I normally use Atom, or VSCode 🙂 I may need to look into others with Clojure.. I was hoping for a simple lein command ex. -watch ... etc.
things like that exist, but that kind of cycle is for languages that don't have a repl
Don't know why, but emacs and I never clicked... 🙂 I try every year to get into it, and ....
I know, right?
And nobody has any sense of how physics engines APIs should work
It's such an easy pure function - seq of items in, seq of items in positions out
I tried to render a graph a few months ago, and the graph actually showed up the page, but then slowly turned in the z-axis and floated away
Hahahahaha
Cursive is life. I wouldn't recommend Atom if you're starting with clojure, it'll be a bit rough around the edges. Emacs if you're already an emacser, or vim if you're already a vimmer will work out pretty well. But if you don't have a previous allegiance to one of those two imo it's crazy to start with anything other than cursive
Yes, i've been using proto-repl. But I'm not sure how to get it to work with my Pedestal app. It only wants to do block execution...? I'm sure I'm missing the obvious 🙂
proto-repl has a "Execute Block" function. So if you do (+ 1 2) then place the cursor at the parentheses, then you can send the code to the repl.
Just having external figwheel repl up, and copying and pasting from a decent editor, is still a pretty efficient workflow
how do I go from "I need org.apache.http.client.fluent.Content" to getting the group id , artifact id, and the latest version ?
usually I google for “apache http fluent maven” and check for the latest relevant artifact
@noisesmith : I was missing the "maven" and getting API docs
aha - yeah, maven is the magic word for finding the artifacts (that or sonatype)
@linicks Sure, you could probably launch a pedestal app in a repl, if it's set up right.
if you load
(defn f [] 1)
(def serv (future (while true (println (f)) (Thread/sleep 1000))))
Ok... So from the repl I run: (def serv (run-dev)), Then make code change, and run (server/stop serv), Then (def serv (run-dev)) again. I wounder If I can setup webpack for a Clojure project..
depending on how you do things and how pedestal does things restarting may be optional
generally, if you change something referenced via a var (a global created with def), you don't need to do anything but re-def to have the new value used
Hi, can I ask clojure related questions here ? I am a beginner to clojure and I am stuck on a problem. I am learning from helsinki uni mooc (iloveponies)
there’s also a #beginners channel
but yes
What is a good library for: * after a user has logged in, what do I store on client/server side so that all future GET/POST requests from this user are passed to the server as "authenticated as FooBar" ?
I don't know what JWT is. I'm using AmazonLogin. Amazon handles auth, I ujuts need, after auth, to somehow store "this browser client has been authed as FooBar"
JWT == “JSON web token”, basically on login you issue a signed token to the client that identifies that user (like with a guid)
JWT is a standard way for an authenticator to assert a set of claims, and for authenticating systems to be able to validate the authenticity of those claims
okay, so let's sse if this works authentication: client -> server , msg = username + password // or some other oauth thingY servedr generates token matching username server sends token T_foobar to client_foobar due to some crypto magic, it's hard to guess/generate T_foobar using only foobar on all future requests: client -> server / every msg also has "i'm foobar, my token is T_foobar" server verifies T_foobar, then processes request as foobar this is all over https, so it's impossible for eavasdroppers to get T_foobar is this all correct ?
also consider adding a lifetime to tokens, so they’re rejected after some amount of time, and possibly have a renew call
http://rundis.github.io/blog/2015/buddy_auth_part1.html lol buddy uses public key crypto for the token
right, that’s standard for JWT
fun fact! JWT has a special NONE cypher, which means no encryption, and at one point a client could just say “hey this is my token it is encrypted by method NONE” and JWT implementations would silently accept it
now every JWT lib guides you toward explicitly whitelisting the cypher you accept
the useful thing is that this means the server can put useful data in the JWT that the client can a) decrypt and use and b) verify that it was definitely made by the server
(of course this isn’t foolproof because an attacher can just edit the code to check for a different signer so don’t count on this)
but at least it protects an honest client from a malicious middleman
(if they get the server’s public key over ssl - man, so many gotchas in crypto)
FWIW I use the Java Nimbus library for my JWT needs; I found buddy too fiddly for what I was trying to do
@donaldball Looks like MS’s Azure OAuth libs use Nimbus. We are using Apache OLTU (Jose) library for JWT elsewhere.
if Clojure's numbers are too low for him, ask him if he thinks it's easier to find housing in a big city than in a small one :)
I’ve looked for it, I don’t think it exists
if your pred?
returns the arg when true and nil/false when not; you can use or
for that (or (my-special-pred? x) default)
; but I don't think there's a core fn that does exactly what you're asking about
(and I don't actually recommend doing it the way I suggested)
Yeah, that would require modified predicates. At that point I'd rather just define this function in my utils file 🙂
let-if
has the same issues as or
, where it captures the output of the your predicate function
I've never bothered to write a helper function for that, since (my-fn pred? x default)
isn't really any shorter or easier to read than just (if (pred? x) x default)
; I guess if you had long variable names, or we're doing some kind of threading of predicates or something, it might make sense though
thats true. also the way the (my-fn pred? x default)
function is defined, its just an if statement anyway
@tanzoniteblack Well (if (pred? x) x default)
is fine, but as soon as x
because an expression it becomes a problem, IMO