This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-07-30
Channels
- # arachne (5)
- # beginners (42)
- # cider (35)
- # cljs-dev (25)
- # cljsrn (2)
- # clojure (107)
- # clojure-dev (32)
- # clojure-finland (2)
- # clojure-greece (3)
- # clojure-italy (6)
- # clojure-nl (7)
- # clojure-spec (27)
- # clojure-uk (45)
- # clojurescript (152)
- # core-async (3)
- # cursive (26)
- # data-science (4)
- # datomic (33)
- # defnpodcast (1)
- # duct (12)
- # editors (3)
- # emacs (6)
- # events (5)
- # fulcro (6)
- # jobs (1)
- # lein-figwheel (9)
- # off-topic (7)
- # onyx (7)
- # re-frame (1)
- # reagent (9)
- # reitit (31)
- # shadow-cljs (130)
- # slack-help (1)
- # spacemacs (53)
- # tools-deps (55)
- # yada (4)
Clojure and ClojureScript will probably never see the meteoric adoption that e.g. Go went through, but it’s a stable language that is excellent at being productive
How does one set the random seed in clojure? I found this, but it seems odd that there’s no way to do it in base (terminology?) clojure https://github.com/trystan/random-seed
I’m aiming to unit test a function that produces weighted random output. If there’s a better alternative that setting the seed, I am all ears
@tsulej Curious. Can an if
chain show why (and)
returns true
or (or)
returns <yikes> nil
? (just checked myself in the repl and got surprised by the latter.)
what do you mean @hiskennyness
@hiskennyness in my opinion yes. After macroexpand you can see precisely what is returned and when.
@dpsutton the question was why or
or and
behave like they behave (ie. or
returns nil
instead of false) and how to figure it out.
I proposed to look at expanded version of both to see how it's constructed (if chains)
and and or can return potentially any value, not just true/false. If you want that, wrap in boolean
I was asking what goes inside (if )
to convey (and)
returning true.
I cannot think of anything for the conditional. I understand (and) => true
as “and returns true if none of its arguments are false”…except no, it returns the last argument. But there is no last argument in (and)
, so now we have to write a short speech: “and returns its last argument if no other arguments are falsey, but returns true if there are no arguments”. Boy that sounds like a hack.
It returns true if all values are logically true
Now with (or)
we have “or returns the first truthy value”. Hellasweet. 🙂
I thought (and 1 2 3) returned 3
Of course “returns first truthy” explains why (or)
returns nil
Sure, but it could also be vacuously false or 42, so we are still trying to explain why true was chosen. Should it be an error?
Oh, thx. Did not know the math/logic meaning.
everyone has this reaction when learning about universal and existential qualifiers in math.
But my original concern was the idea of an if
chain, which I think breaks down in the vacuous case.
yes you are right. If you look at the sources of these the empty cases are handled explicitly.
If I wanted to cast bools to int like this:
(defn bool->int
[b]
(if b 1 0))
would that a) make me a terrible person, and b) is there a better wayLooks ok to me
the name implies a strictness that isn't there about the input type, but that probably doesn't matter
(bool->int 0) => 1; (bool->int nil) => 0
that 0 case will be surprising to people who are used to implicit bool/int overloading as it's used in most languages with the feature
to get a bool->int that is closer to how python/js/ruby/c etc. do it you could try (not (contains? #{nil false 0 0.0} x))
you can add "0"
, []
and ""
to that list... for that little PHP touch
haha, you could add optional compatibility switches that expand / vary the set... :D
I know I’ve asked this same question here before, but ya’lls good answers didn’t quite make it through my thick head, so let me try again: What’s the right way to ask for credentials when writing a library? I’m tempted to use refs/atoms like this example https://github.com/smnirven/biomass/blob/master/src/biomass/request.clj#L16-L25, but this goes against Alex Millers advice at https://puredanger.github.io/tech.puredanger.com/2014/01/03/clojure-dependency-injection/ as well the advice I’ve gotten here. The counter proposal is to use a framework like component or mount, but I don’t want to necessarily lock a user into a framework to access my library. Amazonica gives a bunch of different options listed here https://github.com/mcohen01/amazonica#authentication, none of which seem to fall directly in the “use component/mount” category.
@smnirven, I’d readily welcome a defense of the ref/atom method used in biomass, btw.
@d4hines for credentials that are not related to a persistent connection, why does the library need to worry about keeping them around at all? The most natural thing would be to have the client pass in the credentials with each call.
Dependency injection, component/mount etc. are for when there's something stateful that has to managed, like a connection handle
even in those cases the most neutral thing for the library to do would be offer a connect
-like function that returns the connection handle, and API functions that take the connection handle as a parameter. That way your clients can choose to manage the connection state however they want
some libraries, like "carmine" is the example that comes to mind, offer a sort of mix-and-max approach where there's a flavor of the API that will hold on to a redis connection handle in an atom inside the library's namespace, and another flavor where the client can manage it
I'll second what @michael.gaare suggests - leave acquisition, storage and scope to applications, and let a library take an argument providing any resources needed. And yeah, component is a good choice for the application but the lib doesn't need to care.
direct arguments are flexible in a way that dynamic vars, global state, and stateful objects are not. If you work in terms of immutable args to a function, a user can do the same, or use what you provide to implement globals, dynamics, mutables, etc. - but none of the other solutions are that flexible or universal
Hi, I’m trying to use a JS library that’s not in cljsjs
. (Specifically, https://www.npmjs.com/package/react-edit-inline ) Is :npm-deps
the best (or only?) way to do this? Is writing my own externs file a good way (then I could contribute back to cljsjs) ? What’s the best current way to consume and use that library (among other npm libs…) Any help is much appreciated!