Fork me on GitHub

Fair enough. Thanks all 🙂

Drew Verlee01:12:01

Is there a way to set a validation on data going into an atom? I dont see to see docs for that, but it seems like an obvious thing to have. If not, i'm guessing there is an interesting reason why 🙂

Drew Verlee01:12:34

Maybe you could do this with a watch, but the name implies thats wrong...


@drewverlee atoms have this feature, it's called...


:validator validate-fn


> If the new state is unacceptable, the validate-fn should return false or throw an exception.


in fact I think you could write a validate function to let only prime numbers into an atom and just iterate over all the integers. not the most efficient way to get a list of primes, but maybe that demonstrates how it works

Drew Verlee03:12:57

@sova Your right. Afterwards i realized my question assumed a lot of things about the atom. Namely that it was holding a collection, which your not limited to. In my case, i could build an interface to my atom and restrict the arguments passed to it.


Yeah, the validate-fn will prevent things from getting placed into the atom, but you probably want something that will inform you why it didn't get into the atom in the first place.. depends on what you're using it for


Where can I read an approachable introduction to nREPL vs. stream REPLs? And are the latter the same as socket REPLs?


@echristopherson REPLs are really just a stream of characters in and out. What is known as nREPL is really a RPC protocol over common Clojure interactions.


So a socket REPL is really nothing more than hooking what would normally go to stdin/stdout and piping those over a tcp socket.


Doesn't nREPL go over a socket?

Alex Miller (Clojure team)05:12:36

yes. socket is really orthogonal to stream vs a framed protocol like nrepl

Alex Miller (Clojure team)05:12:00

streams are just streams of text

Alex Miller (Clojure team)05:12:49

nrepl is call and response with data structures

Alex Miller (Clojure team)05:12:07

Clojure includes a socket server on which you can supply a listener function. one provided and common function to use is a stream repl listener.

Alex Miller (Clojure team)05:12:28

You could also supply a listener that accepted the socket and talked using the nrepl protocol instead


Oh, framed protocol. Gotcha.


The stream way is seen as preferable now?

Alex Miller (Clojure team)14:12:26

They both have advantages


streams are more low-level, thus they need more work to integrate into but they also provide more power


you can implement nrepl on top of socket repl but not vice versa


hello, is there an easy way to replace a sublist of a list with its reverse? for example in (1 2 3 4) replace the (2 3) part with its reverse, and get: (1 3 2 4)


I think (transform (srange 1 3) reverse [1 2 3 4]) will do just that, let me check


thank you 🙂


looks like an awesome lib


it is extremely useful for certain problems


What's the easiest way to create a function f with the property that (f coll g) is the element x of the collection coll for which (g x) is maximal?


I thought that maybe I could map g over coll and then zip the results with coll go get a map, then call max-key, finally look it up. But that seems way too complicated for such an apparently simple operation 😞


(defn f [coll g] (last (sort-by g coll))) is an inefficient but terse way


(defn f [coll g] (second (apply max (map (juxt g identity) coll)))) might work


Any reason why the first one in inefficient? @donaldball


You don’t need to sort, you just need the max


I think I just realized in the documentation of max-key, the name k stands for a collection, not a map. Thus perhaps max-key is the function I am looking for!


ha ha maybe 🙂


Alas, it doesn’t compare generally, it assumes the codomain of g is a number


For the record, max-key is not quite it. For example, (max-key count [[1 2] [3 2 4]]) does not work. You need to do (apply max-key count [[1 2] [3 2 4]]) to obtain [3 2 4] which is what I originally wanted.


quick question y'all, when throwing a custom exception eg with (throw (Throwable ... why is Throwable. or Exception. with a period? What difference is that without a period?


That’s how you instantiate a Java class


Check this out if you want some in depth info


@admay I mean, what's the difference between Throwable and Throwable.


nvmd i see, the dot means any args to the right of it are passed to the contstructor


whilst without the dot is just the Java class


just a macro to suger up (new Class args*)


user=> (throw (Exception. "Foo"))

java.lang.Exception: Foo
user=> (throw (Exception "Foo"))

             java.lang.RuntimeException: Expecting var, but Exception is mapped to class java.lang.Exception
clojure.lang.Compiler$CompilerException: java.lang.RuntimeException: Expecting var, but Exception is mapped to class java.lang.Exception, compiling:(/private/var/folders/95/bq20sfr15kbbnw_z3j8njxw54nfw83/T/form-init5049763821089224505.clj:1:8)


With the dot, you get a java ‘thing’. Without the dot, Clojure will look for a symbol called Exception (and in this case fail) 🙂


user=> (type Exception)