This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-09-02
Channels
- # admin-announcements (21)
- # announcements (1)
- # boot (128)
- # cider (18)
- # cljs-dev (10)
- # clojure (112)
- # clojure-brasil (2)
- # clojure-italy (4)
- # clojure-japan (12)
- # clojure-russia (38)
- # clojurescript (241)
- # clojutre (1)
- # datascript (2)
- # datomic (3)
- # events (1)
- # hoplon (38)
- # jobs (1)
- # ldnclj (5)
- # melbourne (8)
- # off-topic (2)
- # om (9)
- # re-frame (13)
- # reagent (43)
- # sneer-br (24)
- # sydney (3)
Does anyone know how to check for authentication during a sente handshake (ajax-get-or-ws-handshake-fn) and reject the connection if the auth params aren’t kosher?
Oh wait. It’s just a ring request. So I guess I can wrap my own handler to check the headers and only call that function if things are good…interesting.
I think I'm finally starting to really understand the functional way of coding:
(defn fibonacci-sequence-simple
"Returns a lazy sequence."
[]
(let [rules {:axiom [0]
0 [0 1]
1 [0]}
xform (mapcat #(or (rules %) [%]))
rfunc conj
trans (partial transduce xform rfunc)
axiom (trans [:axiom])
gener #(trans %)]
(iterate gener axiom)))
(comment
(take 5 (fibonacci-sequence-simple))
)
And I finally figured out how to really leverage transducers in these L-Systems I've been working on.
Here's a start:
(defn replace-xform
"Returns a transducer that will apply the replacement rules to a word."
[rules]
(mapcat #(or (rules %) [%])))
(defn system
"Returns an L-system."
([xform]
(system xform conj))
([xform rfunc]
(let [trans (partial transduce xform rfunc)
axiom (trans [:axiom])
gener #(trans %)]
(iterate gener axiom))))
(defn fibonacci-sequence-simple
"Returns a lazy sequence of Fibonacci integers OEIS A003849."
[]
(let [rules {:axiom [0]
0 [0 1]
1 [0]}
xform (replace-xform rules)]
(system xform)))
Opportunity grants available for Clojure/conj http://clojure-conj.org/opportunity
(defn system
"Returns an L-system."
([xform]
(system xform conj))
([xform rfunc]
(let [gener (partial transduce xform rfunc)
axiom (gener [:axiom])]
(iterate gener axiom))))
A friend of mine has to benchmark a JVM with 1 terabytes of heap. He'd like to do it in Clojure. What algorithm would you suggest?
Now things are really shaping up nicely:
(defn replace-xform
"Returns a transducer that will apply the replacement rules to a word."
[rules]
(map #(or (rules %) [%])))
(defn call-without-arguments-xform
"Returns a transducer that will call any function without passing arguments."
[]
(map #(if (fn? %) (%) %)))
(defn system
"Returns an L-system."
([xform]
(system xform conj))
([xform rfunc]
(let [gener (partial transduce (comp xform cat) rfunc)
axiom (gener [:axiom])]
(iterate gener axiom))))
Which lets us start to do more interesting things, like this (which is still simple but should give a hint about where I'm heading):
(defn fibonacci-sequence-stochastic
"Returns a lazy sequence of Fibonacci integers starting with 0 or 1."
[]
(let [rules {:axiom #(vec [(rand-int 2)])
0 [0 1]
1 [0]}
xform (comp (replace-xform rules)
(call-without-arguments-xform))]
(system xform)))
And now I've finally dealt with that nagging feeling that I just wasn't taking advantage of transducers the way I should have. Hurray!
These things can really generate some seriously big sequences quickly:
(-> (fibonacci-sequence-simple) (nth 35) count)
=> 24157817
@luxbock: thank you! I am so much happier with the code now. Check it out: https://github.com/decomplect/ion/blob/master/src/ion/ergo/l_system.cljc
The old code is still in the file at the bottom so its easy to compare the two. The old code supported the general API that I wanted, but the implementation was kind of ugly and rigid. The new code is what I had in mind all along and struggled to flesh out. What I wanted was really a toolkit of useful functions and transducers and some reference implementations for building L-systems and some examples that did crazy things that push the boundaries to open people's eyes to what is possible. I think the new code is coming much closer to what I imagined and was hoping to achieve.
Is there something in the observation that transducers seem to pull all the functions to the left and leave a single seq/coll at the right? Is that even correct? Just trying to get my head around them ...