This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-05-05
Channels
- # aws-lambda (1)
- # beginners (294)
- # boot (35)
- # cider (19)
- # cljs-dev (39)
- # cljsrn (7)
- # clojars (48)
- # clojure (266)
- # clojure-android (1)
- # clojure-brasil (1)
- # clojure-france (2)
- # clojure-greece (5)
- # clojure-italy (7)
- # clojure-mexico (1)
- # clojure-russia (24)
- # clojure-spec (10)
- # clojure-uk (31)
- # clojurescript (134)
- # consulting (7)
- # cursive (69)
- # datomic (20)
- # emacs (57)
- # events (2)
- # figwheel (2)
- # hoplon (1)
- # jobs-discuss (19)
- # luminus (33)
- # lumo (18)
- # mount (1)
- # off-topic (32)
- # om (5)
- # onyx (27)
- # pedestal (15)
- # re-frame (12)
- # reagent (28)
- # rum (2)
- # schema (2)
- # spacemacs (9)
- # unrepl (2)
- # untangled (7)
- # vim (5)
- # yada (4)
sorry is this is a tired old question, what is the right and proper type to extend a protocol with if I want this implementation to be called for all kinds of core.async channels?
@arthur are you looking for clojure.core.async.impl.protocols/ReadPort and WritePort ?
that is what I needed to check for to write a chan?
function
if the first argument to the implementation function is any kind of chan, then this function should be called
there’s also Channel (same namespace)
I don’t remember that existing when I wrote my chan? predicate, it would have been the natural thing…
oh wait, the ports were totally wrong, I’m misremembering something
double self correction, heh
=> (supers (class (clojure.core.async/chan)))
#{clojure.core.async.impl.protocols.Channel java.lang.Object clojure.lang.IType clojure.core.async.impl.protocols.WritePort clojure.core.async.impl.protocols.ReadPort clojure.core.async.impl.channels.MMC}
how do I go about referencing the previous state of an atom?
@grounded_sage when you change an atom via swap!
or reset!
, you can use a watch to get the old value https://clojuredocs.org/clojure.core/add-watch
@grounded_sage also, an upcoming release of clojure will have support for accessing the previous version using swap, instead of the new version. in the meantime, see something like this: http://stackoverflow.com/questions/43599473/get-the-state-of-an-atom-and-reset-it-atomically/43599982?s=3%7C0.0000#43599982
beyond that, from a 10 second glance at the java code, once an AtomicReference
is set, there's no looking back at the previous value
@joshjones you mean like you can swap back to a previous version? That definitely sounds good. Pretty much what I am needing to do now. Swap in some new content but then swap back.
https://dev.clojure.org/jira/browse/CLJ-1454 has an implementation of this
you can find a less invasive impl in something like this: https://github.com/overtone/overtone/blob/e200075da27375727db1f5ce342e2e1c22ea1dbd/src/overtone/helpers/ref.clj#L6
as posted above @grounded_sage , this will return the prior value:
(defn reset-return-old!
[atm new-value]
(let [old-value <@U169ZE1J4>]
(if (compare-and-set! atm old-value new-value)
(do
(.notifyWatches atm old-value new-value)
old-value)
(recur atm new-value))))
You can then do whatever you like with it.. this is just a reset
, but swap
is the same ideaHi all, does anyone know of a natural language API similar to IBM Watson’s personality insights? What I’m looking for is a service that analyses unstructured text, but does more than just sentiment analysis or entity extraction, and whose results are more directly useable
@achesnais this would be a good discussion for #off-topic
does clojure havea function which captures the idea of: here's a list of functions, try them all, in this order, and return me the firt one that succeeds
Curiousity question ... Is anybody here using clojure in an enterprise/large corporate distributed system way? .. if so, what kind of system architecture did you use? Micro-services?
at this stage, enterprises still tend to prefer java/.net and object-oriented designs
if you want to know more of what I mean by enterprise/large corporate... imagine a large bank
lincpa: qqq: there’s also some-fn, but neither of these returns the function (which is how I initially read the question)
(ins)user=> (some #(% 2) [list? odd? even?])
true
(ins)user=> ((some-fn list? odd? even?) 2)
true
How do people solve indentation issues in a team? The problem: team members use {Atom, IntelliJ, Emacs}. True to its name, my Emacs's aggressive-indent mode reformats code it touches (or it seems just sees) with much enthusiasm, leading to diff noise. How do you approach this technially trival yet socially complex issue?
Although that either means you need to include cljfmt in your build pipeline (with a potential commit if you use fix mode) or add git hooks to run it.
You can customise the indent policies on most of those editors (including emacs) so you could produce std formatting across all editors.
@mpenet relies on ppl remembering tho
tabs vs spaces is usually something u set in your editor tho. So fire and forget. cljfmt plugins are good way to go
Cursive differs a bit around alignment of vars
but both can be customised
yeah I was wondering how an automated tool might fit in
The main point of contention is indenting function arguments, essentially boiling down to the three options laid out here: https://github.com/clojure-emacs/clojure-mode#indentation-options - always-align, always-indent, align-arguments
git status
-> take the changed files -> Use lumo + clj-fmt to rewrite the files. That could be nice.
why lumo? because it's faster?
@pesterhazy If you're using the right GIT indentation config, I think that issue would go away...
what's git got to do with it?
we're using git, but can you point me to a reference where git reindents lisp code?
see if this helps at all : http://stackoverflow.com/questions/2316677/can-git-automatically-switch-between-spaces-and-tabs/2318063#2318063
tabs v spaces is not the issue in our team. 2 spaces have won the battle luckily 🙂
in which case, I have nothing other than perhaps to have the team try to standardize their preferences 🙂
some editors use this style:
(some-function 10
1
2)
others (such as clojure-mode by default) use this style:
(some-function 10
1
2)
if two people using those two editors work on the same code, you pingpong back and forth between the two
perhaps just a matter of choosing a style and putting effort into configuring the tools to match up
right I think that's what it boils down to
perhaps aided by a cljfmt or boot-fmt style
gonna give cljfmt a spin
any suggestions for fast off-heap (preferably, but not necessarily directly on disk) storage of clojure maps? (the assumption being that the data is too large to fit in memory)
mbjarland: https://github.com/ptaoussanis/nippy ?
yeah nippy is good for what it is but as the data does not fit in memory you would then end up doing some kind of management manually
i.e. persist one submap per file or something, I was hoping there would be something out there for managing data sets larger than what fits in memory...looking into the datomic dev mode (disk storage), could be an option
also looked at map-db with and without a nippy serializer and at carmine (redis api for clojure) but turns out redis requires your data set to fit in memory so that invalidated that option
Maybe just throw it into a database? You could even convert it to json and use postgres json column feature if you dont want to add datomic to your stack
I thought transit wasn't recommended for storing data? >"NOTE: Transit is a work in progress and may evolve based on feedback. As a result, while Transit is a great option for transferring data between applications, it should not yet be used for storing data durably over time. This recommendation will change when the specification is complete."
datomic is nice...if you are ok with locking yourself into a model where you would be shelling out $5k for a license after a year
so say I have small maps (fuzzily a couple of screens in a repl), but I have a million of them...or some large number
am I correct in assuming that transit, nippy, fressian would all mean that you would be managing the top level keys yourself somehow, and perhaps storing a file per small map or something similarily home-cooked
ok so perhaps there is no "one ring to rule them all" answer to the question, sounds like I'll have to do some digging, use datomic (and drink the cool-aid), or revert to storing things in a database as suggested
one thing that strikes me as strange though, on the hitchhiker site they state that "Outboard is a simple API for your Clojure applications that enables you to make use of tens of gigabytes of local memory, far beyond what the JVM can manage" and then they provide a redis backend...with redis "data sets that can't be larger than memory" as per redis documentation. Confusing state of affairs there...
https://github.com/JetBrains/xodus seems like a potentially viable candidate as well
If you have many small maps then I'd just use leveldb and nippy serialization. Also all depends on your req/s read/write.
yeah, that sounds like a viable option, I'll create a sample project and try it out
change the version number in project.clj
then lein install
Is this an acceptable way to use a macro:
(defmacro only-without-nil
[ex]
(if (some nil? (rest ex))
nil
ex))
=> (only-without-nil (+ 2 4 6 nil nil 5))
nil
=> (only-without-nil (+ 2 4 6 10 5))
27
so basically what @bostonaholic said
thanks @bostonaholic and @zylox
yup, np
Hi, any know big web project in clojure on github or bitbucket?
Is there a way to conditionally assoc a value into a map literal?
so instead of
(merge
{:foo "foo"}
(when x {:x x})))
something like
{:foo "bar"
(when x :x x)}
Thanks @bronsa
I wonder, is there any correct usage of merge that can’t be replaced with conj?
I guess trivially there’s (merge) => nil and (conj) => []
but if you have a hash map as a first arg, I think conj works for everything merge handles
also map conj errors would make a lot more sense if conj didn’t accept another map
(because the last thing it tries is to treat the arg as a hash-map, so that’s the one you see in the error message)
but that horse is out of the barn, no version of clojure will change that behavior
@noisesmith what error are you referring to?
(ins)user=> (conj {} (list :a :b))
ClassCastException clojure.lang.Keyword cannot be cast to java.util.Map$Entry clojure.lang.APersistentMap.cons (APersistentMap.java:42)
it wants keyword to be a map entry because it wants the list to be a map
and that’s the last failure, so it’s the one reported
very counterintuitive
I think the surprise-factor to me with conj
behavior on maps is just that it accepts other maps
(conj {} [:a 5] [:b 6])
that is normal conj
-like behavior on a collection. It is adding items (entries) to a collection (the map)
wow - that’s weird
at the repl, the compiler will for some "simple" expressions choose to try and interpret code instead of compiling it
and the interpreter effectively uses apply to invoke functions, which the reify is missing
(def one ((fn [] (id 1))))
the extra fn here forces the compiler to actually compile the code which then works
ahh, so you could fix it by implementing applyTo for it, right?
is it idiomatic for custom types that implement IFn to define all arities and throw a custom exception when behaviour is undefined ?
I am usually pretty lazy about it and just implement the arity of invoke I want, but I've also never run in to that error before
>at the repl, the compiler will for some “simple” expressions choose to try and interpret code instead of compiling it @hiredman this seems weird to me. The main Clj REPL is doing this? Going through the “apply” flow instead of direct invocation? That’d be interesting to look at. Never heard of it.
sure, there are vestiges of an interpreter in the compiler, which the compiler uses for very simple expressions at the repl
the rules for that are something like: only for top level forms, only for defs, only for defs where the value is directly result of a function call, and only when the arguments to the function call are also simple
is it safe to assume that *ns*
in the context of macroexpansion is the namespace being expanded at the time?
to be pedantic, namespaces aren’t expanded, forms are expanded, and if they use defining forms *ns*
is the namespace they mutate
which is basically yes - that is where the current definitions will end up unless they use something wacky like intern
it seemed like @pesterhazy’s real question was how to solve the social problem of code formatting, which i don’t think anyone answered, but is definitely the more interesting and challenging one. i wish i knew the answer to that. some possible strategies: 1. appeal to community standards--if there is a most popular style, just use that. e.g. maybe there’s a reason :always-align is the clojure-mode default. 2. let the person with the most experience in the language be the authority.
just like with lots of engineering decisions, sometimes people can’t reach a consensus on their own, and someone needs to be the authority that makes a decision for everyone.
good and eponysterical points @wiseman
@wiseman cljfmt answers that with “everybody uses what the tool says is right”
which is what my team adopted, I have not regretted it at all
@noisesmith there are definitely tools that have opinions about code that i don’t think everyone, or even most people agree with. it sure can help to have a “community standard”, which is what ideally something like cljfmt would embody
that's the path I'm going down right now
the tool respects bbatsov's guide, so there's double authority there (human & machine)
right, it didn’t invent it’s rules out of a vacuum, it implements human invented best practices
haha - but that is the current community consensus - you can create more lines with comments
I have a directory of .clj .cljs *.cljc filles. I want to count "lines of code", but not use wc -l . What is suggedsted ?
@qqq http://cloc.sourceforge.net/ supports clojure
https://gist.github.com/andrewvc/3161953 <-- this is the first result on google
@qqq there’s an app, cloc, you can get it via however you usually get command line apps, it supports clojure
I get it via homebrew
(or apt at home)
you mean that’s the output
you probably wrote a lot more :)
if P = NP, I could have just written the correct 1.2k lines of code and ignored all the churn
https://github.com/clojure/core.match/wiki/Basic-usage <-- are there more detailed examples of guards?
actually this might get better by lazily evaluating the original collection which produces the list of booleans
but that will be too specific to and
, while or
would require a differently looking expression
ghadi: Wait, how is every?
lazy?
not lazy! (but short circuiting)
(via reduced that is)
kind of annoying that and
is a macro, so we can't
(apply and my-list-of-booleans)
I thinkhonestly if it doesnt occasionally throw an exception based on the current millis are you even trying?
@matan otherwise it can’t short circuit
not preventing its args from being evaluated
maybe this could work (reduce (fn ([] false) ([x y] (and x y))) my-list-of-booleans)
@jfigueroa the standard definition is that every item in a collection matches the predicate, if there are no items in the collection
which means the first arity can be skipped, by starting with true as the init
for short-circuiting, (reduce (fn [_ x] (if (nil? x) (reduced x) x)) true [])
getting kind of ugly…
well in Scala 😛
collection.forall(identity)
// and a collection
collection.exists(identity)
// or a collection
matan: is that and / or or is it find-one / is-every? because and and or short circuit and prevent args from being evaluated
(and nil (System/exit 0)) - jvm does not shut down
my eyes are bleeding