This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
- # admin-announcements (24)
- # alda (1)
- # aws (10)
- # beginners (15)
- # boot (51)
- # cider (37)
- # clojure (198)
- # clojure-berlin (3)
- # clojure-czech (48)
- # clojure-poland (1)
- # clojure-russia (7)
- # clojure-seattle (1)
- # clojurescript (347)
- # editors (64)
- # emacs (46)
- # hoplon (13)
- # immutant (24)
- # jobs (17)
- # ldnclj (20)
- # ldnproclodo (3)
- # off-topic (8)
- # om (37)
- # onyx (19)
- # re-frame (18)
- # reagent (54)
- # remote-jobs (2)
- # testing (9)
- # yada (1)
- # yleinen (4)
in repl we could use *1 to get the last value. But after I feed a new express, then *1 changed to the new last value. in scala, it use res0 to get the first value, res1 for the second value, etc. and there is no limit about how many old values to retrieve, but *4 will throw error, only *3 is available, do we have other way to get more historical value in REPL?
@wqhhust: I don’t think so, but you could look at something like gorilla-repl if you’re wanting to do more historical exploration
however it is possible to customize the repl function to do that :)
Are there any good references or implementations using Protocols and Records for working with points? I need something beyond the absolute basics, like figuring out if/when my functions should be written expecting an arg to be a Point vs. a vector containing an [x y] value, etc. And dealing with having sets of points and vectors of points, etc.
for clj-webdriver, do way we have a way to find out how many rows a table have? in taxi api, it have many function, but none of them could get how many rows a table has or how many columns a table has.
And points with additional fields, like a Cell representation for cellular automata where a Cell might have fields for [x y age color neighbors]
How's this for generic?
([get-xf prep seed init] (letfn [(process [coll] (lazy-seq (when (seq coll) (let [new-coll (into (init) (get-xf coll) (prep coll))] (cons new-coll (process new-coll))))))] (process (into (init) (seed))))))
the most important question is: do you care about primitive math? (boxed math is 100x slower)
so if you want prim math, you must use either Java arrays or deftype/defrecord (where you can use ^long and ^double hints)
([get-xf prep seed] ; Useful default for cellular automata. (produce get-xf prep seed #(set nil)))
So I need to figure out the protocols I need and the defrecord for Cell. Then I need to change the functions used in the transducing stack.
I'm tired so I might be misspeaking, but I don't think protocol methods support primitives either
a good trick is to use definterface to create a Java interface with primitive type hints, then implement that in a deftype or defrecord
I need to figure out what to change so that my existing functions work with a Cell defrecord, or change the functions as need be, such as these:
(defn neighborhood-8 [[x y]] (map vector ((juxt inc inc identity dec dec dec identity inc) x) ((juxt identity inc inc inc identity dec dec dec) y))) (defn prep-8 "Returns a map of [x y] n pairs." [cells] (frequencies (mapcat neighborhood-8 cells)))
this is an area where performance optimizations fight with simplicity/readability
I just figured even a simple defrecord or deftype has to be better than vectors with x,y pairs.
you might look into some of the array libs too like hiphip (array!)
But what I haven't seen examples of is how a Point or Cell record behaves when put into collections like set. And I use set membership behavior for the CA logic, ala:
(defn exist? "Returns a cell if destiny will allow, or mother nature brings it to life." [birth? survive? cells [cell n]] (if (cells cell) (when (survive? n) cell) (when (birth? n) cell)))
by "like maps" I mean "equality comparison by value", just like all the other Clojure collections
I suppose some of this code would just work, but what I really want is for (->Cell 5 6 :red) and (->Cell 5 6 :blue) to be considered equal since they have the same x,y values. Does that make sense?
In Python I would customize the class and overide the hash__ method or something like that (can't remember any more, but I used to)
So that attempting to put both of those cells into a set would fail for the second cell, but that only works if the hash value ignores the color field.
@tcrayford: read some of your blog posts today and watched the video of your presentation - good stuff.
right, so I would need to use deftype because defrecord's implementation of map protocols would get in the way
I'm also wondering how I should model a Cell. For example, I could make it an isa? of a Point, meaning something like deftype Cell [x y color age] or I could say that a Cell contains a Point and additional fields. But I don't know if that is possible or advisable.
@meow: depending on performance concerns, I'd typically just use a map and write some functions that work on the map. Depends what you're doing though
I'm guessing for performance reasons a simple, flat structure would be best. But the object/database modeler in me isn't sure.
but, if you're concerned about perf, yeah, simple flat deftype seems like the best thing for that from my perspective
it depends on the nature of the codebase and the problems you're trying to solve as to "is a nicer model more important than performance" 😉
@tcrayford: I've got a library for constructing L-systems and cellular automata where for the CA stuff the cells are just represented as [x y] vectors and I want to change it to use deftypes and protocols for two reasons: performance and so that the cell can have additional fields, like age and color and neighbor counts and whatever else someone using the toolkit might want to define.
The L-system is pretty much done and only needed a Protocol, so that was easy. The CA stuff needs to go from [x y] to a Cell deftype and then I don't know if my code should extract an [x y] out of the Cell and use that on the existing function, or whether the function should be rewritten to expect an object the satisfies? some protocol.
@meow: another potential nice solution there: implement nth for your deftype, then all your existing list destructuring code will work
@tcrayford: aha! I think I know what you mean. You're saying if Cell is a deftype and implements
nth and I leave
y as the first two fields (or make it work out that way in the
nth implementation) then if I pass a Cell as an arg to an existing function that does a
[x y] destructuring that it will continue to work because behind the scenes the destructuring is calling
nth on the object. Interesting. I hadn't really thought through how the destructuring sugar works. That's a great tip, thanks.
And that means I wouldn't have to change any of the existing functions, so they can support either an [x y] pair or a Cell or anything that implements
nth in a similar fashion. Sweet!
That was definitely a missing piece for me was how to make a new deftype not completely disrupt the existing code or force me to change the code so that it no longer worked with something that wasn't a Cell type.
is there a built-in that given an overloaded predicate and a seq returns a seq of 2 seqs, one for true-like values and one for false-like?
group-by because the predicate doesn't return true and false, it returns something or nothing (false or nil). It's not
filter because we want the false ones too. Something like juxt filter remove maybe?
sure. If you had a predicate that could return 1, 2, 3, false and nil and a seq on which the predicate works, make it so that the seq is divided into 2 - one for the "true" results like 1, 2 or 3 and one for the "false" results like false or nil
anyone got an idea what would trigger "ClassNotFoundException: java.sql.SQLType” on a clojure.java.jdbc INSERT
@joost-diepenmaat: the obvious thing would be Java version. java.sql.SQLType was introduced in Java8, so if you’re using Java7 or older it won’t exist
ah that may explain why it works in development but not in the production environment
I thought I picked the correct version of the JDBC driver for 1.7 but maybe not… should 9.4-1203-jdbc41 not work with java 1.7?
anyone using Pulsar? I’m interested in using it in the next project because it looks awesome. I just don’t know what to expect in the long run.
@nooga: I haven’t used it, but I just saw this post today http://www.deadcoderising.com/2015-09-22-concurrency-made-easy-with-clojure-and-pulsar/
I’ve read about Pulsar actors and they look like a great architecture for what i’m planning
my only fear is that Pulsar may turn out to be slow, bug ridden or not really maintained
nooga: they're definitely not slow. Ron Pressler is quite the engineer. His demo at at the jvm language summit a couple years ago was impressive
in emacs I would put the cursor between the last two brackets and execute sp-forward-barf-sexp
the rest of paredit can be expressed with just
M-) and creating parens, so there's no need to learn any more 😉
@thomas: I’ve been using emacs for several months now and IIRC it felt natural after a week or two, the rest is exploring different commands and clever ways to do stuff
@nooga - I think there is a bit of snobbery around building your own config. If it works for you, why rock the boat? Sure, there is learning etc. And the other perspective is that you have built your own config by modding emacs-live
well, sure, but there are things with modules that e-l does, which I don’t understand and I have to rely on the updates from its maintainers
yeah, I didn’t last too long with e-l for a similar reason. I moved over to prelude and things were a lot smoother. My starting assumption is that I didn’t spend enough time so any issues with e-l are mine, but prelude config seemed closer to the metal, if you see what I mean
@yogthos: maybe you have some experience with Pulsar? (http://yogthos.net/posts/2015-06-17-Using-Pulsar.html) I’m planning to put it into use in my mission critical project and wondering if it’s a wise move.
@nooga: the guys making it are dogfooding pulsar, so it shouldn’t have any glaring problems
the main gotcha is that you have to package the agents, but that’s not too bard using lein
@tel: they follow two different concurrency models. core.async implements CSP and pulsar implements actors
they are similar in the sense that they try to solve similar fundamental problems, but they provide very different abstractions for them
I see. I always think of CSP as being a strict superset of actors, but there’s a lot here to make them more convenient
if you mean superset as in "CSP can implement actors", I think that's right. But that might not be a good idea since you are passing on a bunch of benefits (mostly related to distribution and fault tolerance) that could be gained from actors.
exceptions across thread boundaries can sometimes bite ya. A lot of folks I've seen turn them into data
async exceptions are notoriously challenging, but pretty essential for the kind of distributed computing that erlang offers
but most of what I know that makes them challenging arises from them being able to be thrown halfway through important operations
@tel: gotcha! I am a big fan of your random comments on HN and reddit about type theory and Haskell and math and whatnot…nice to see you hanging around here! And you sent me a wonderful response to an email once re: one of your blog posts