This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-09-01
Channels
- # admin-announcements (11)
- # announcements (1)
- # beginners (1)
- # boot (36)
- # cider (8)
- # cljs-dev (13)
- # clojure (65)
- # clojure-berlin (18)
- # clojure-russia (54)
- # clojurescript (137)
- # code-reviews (3)
- # datomic (30)
- # emacs (9)
- # events (13)
- # hoplon (36)
- # jobs (1)
- # ldnclj (4)
- # melbourne (15)
- # off-topic (2)
- # om (4)
- # re-frame (5)
- # reagent (25)
- # sydney (3)
- # testing (1)
@ghadi: Thank you! I think I have a legitimate need, but wanted to check if it is a strict no-no, or any downsides.
is it possible to gracefully cancel a future using future-cancel
or should I stick with using an atom/promise to notify when it should sotp
Hello! Anyone know cool library, which can make recursive diff's between clojure edn maps and have ability to apply diffs? My goal is sync big map structure between client and server by passing diffs
clojure.data/diff
@jrotenberg: yes, i agree with @plexus, clojure.data isn't convenient for my purposes
Is anybody familiar with io.aleph.dirigiste.Pools.java? https://github.com/ztellman/dirigiste/blob/master/src/io/aleph/dirigiste/Pools.java. I’m trying to understand the semantics of utilization in the utilizationController.
@serce I think you're looking for https://en.wikipedia.org/wiki/Conflict-free_replicated_data_type - here's an interesting talk related to it: https://www.youtube.com/watch?v=3QR8meTrh5g&index=16&list=PLZdCLR02grLoBx0Y5ZrpdmLxc160PIwzQ
@serce if you find one tell me too 😛 clj-diff wasn’t general enough for me either 😞
I need a sanity check on some code I've written. It's an L-system, or Lindenmayer System, which is a simple rewriting system. The code does exactly what I want it to do to support an API that allows replacement values to be functions that will get called as well as replacements that can have optional state data associated with them, also know as a Parametric L-System. The question I have has to do with how I keep track of this optional data internally by using an atom that I pass into another function that is expected to update the atom. It works, but I'm just not sure it's the right way to go.
The code is here: https://github.com/decomplect/ion/blob/master/src/ion/ergo/l_system.cljc
the main function that gets called iteratively looks like this:
(defn process
"Returns new [word state] pair resulting from rewriting each module in the
original word and updating the properties in state."
[rules generation word state]
(let [new-state (atom {})
new-index (atom (int 0))
rewriter (partial rewrite rules generation word state new-state new-index)
new-word (doall (mapcat rewriter (map vector (range) word)))]
[new-word @new-state]))
And the rewriting piece looks like this:
(defn rewrite
"Returns [module] or a successor module if module is found in the rules
mapping. If successor is a function it will be called."
[rules generation word state new-state new-index [index module]]
(if-let [e (find rules module)]
(let [successor (val e)
successor (if (fn? successor)
(successor generation word state index module)
successor)
successor (split-successor successor new-state @new-index)]
(swap! new-index + (count successor))
successor)
(do
(swap! new-index inc)
[module])))
@meow: Why the cast to ‘int’ in (atom (int 0))? I don’t think an atom can hold a primitive?
it can't hold a primitive
it will be boxed by the jvm
https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Atom.java#L18 is where the value is held
the AtomicReference will hold an object - will be a Long in this case
Okay, that was leftover from me thinking I might try to use data.int-map for the state map, but int-map doesn't exist in cljs and I want to use this code in cljs as well.
Anyhow, it just feels like I've compromised my lower level functions by expecting them to update the atoms I'm passing to them. On the other hand, the code is easy to understand and it works and I'm not sure the low level functions are useful elsewhere anyway. They're really just specific applications of replace
anyhow. But am I missing something here? I don't have that much experience with purely functional code.
Actually, this is the really evil function:
(defn split-successor
"Returns a sequence of modules, updating new-state with any successor data."
[successor new-state index]
(doall
(for [[n, module] (map vector (range) successor)]
(if (list? module)
(let [[module data] module]
(swap! new-state assoc (+ index n) data)
module)
module))))
generally I strive to make as many functions as possible pure functions that take data and return data and as few as possible aware of state
So you can define a grammar like this:
{:axiom ['(:A {:age 0})]
:rules {:A #(vec ['(:B {:age 0}) :- (list %5 {:age (age %3 %4)}) :- '(:B {:age 0})])
:B (fn [g w s i m] ['(:A {:age 0}) :+ (list m {:age (age s i)}) :+ '(:A {:age 0})])}}
welcome :)
It just has a few functions that aren't pure but I'm not sure making them pure is going to be a big improvement.
Hey, thanks @alexmiller Most of my coding is in Clojure these days. This seems like a great resource.
it is, glad you found it :)
@malcolmsparks: thank you, i will look into it
@pupeno feel free to email me, or to post something at https://groups.google.com/forum/#!forum/aleph-lib if you have questions about Dirigiste
Can anyone help with this problem of params inside a POST disappearing? And less importantly a problem with response being a single semicolon. -> https://gist.github.com/not-much-io/764c5bb5b46c804b6a42
Conj tickets are on sale now https://ti.to/cognitect/clojure-conj-2015
@not-much-io: cljs-ajax defaults to transit so you might want to add :format :json or something like that. Then you can use wrap-json-params to add the body to :params
or, if you want to use transit you can perhaps use https://github.com/jalehman/ring-transit instead
@jonas: Thanks, I will try json.
@not-much-io what @jonas said. To help in debugging but also as a ring logging solution you might want to check ring-logger (shameless plug)
just for the record, (take 15 (iterate (partial replace rules) '[a]))
does not work the same, close, but no cigar
does anyone use monroe as their emacs nREPL client? recently started having problems with exceptions not displaying in the REPL buffer.
Question: Do you generally just write (Date.)
or do any of you use a wrapper library for this?
I’m not super familiar with Java’s Date stuff, but it doesn't look like very idiomatic Clojure. I’m guessing clj-time is much more pleasant to use for more most use cases.
I guess the choice depends on what you’re doing. For an API wrapper I wrote recently, I’m hesitant to pull in clj-time
as a dep, and thinking I just might use java Date
/ Calendar
myself.