aphyr / dom-top Goto Github PK
View Code? Open in Web Editor NEWUnorthodox control flow, for Clojurists with masochistic sensibilities.
License: Eclipse Public License 1.0
Unorthodox control flow, for Clojurists with masochistic sensibilities.
License: Eclipse Public License 1.0
sup! First of all, awesome library and I'm not judging anyone for their unorthodox control flow views.
Second of all, there's a typo in the loopr
docstring
Line 728 in 375df63
(let [[count sum] ...
Third of all, I observe that a transduce is 20-30% faster than loopr:
(transduce
cat
(fn ([[count sum] x] [(inc count) (+ sum x)])
([[count sum]] (/ sum count))
([] [0 0]))
[[1 2 3] [4 5 6] [7 8 9]]) #_5
There's a clj-kondo analyze-call
hook I created for your excellent loopr
macro, here.
Apparently libraries can export clj-kondo configs, but unfortunately I don't have the time to wrap this up in a nice PR right now.
Hi Kyle,
Not a big deal but noticed there's a swap file checked into the repository here.
Thanks for sharing your "dirty little functions" with the world! ๐
I was macroexpanding some of the test cases to get an idea of what loopr does, when I noticed this:
(loopr [sum 0]
[x (int-array [1 2 3]) :via :array]
(recur (+ sum x)))
expands into this:
(let*
[sum
0
res-7471
(clojure.core/let [x-i-max-7473 (clojure.core/alength
(int-array [1 2 3]))]
(clojure.core/loop [x-i-7472 (clojure.core/int 0) sum sum]
(if (clojure.core/= x-i-7472 x-i-max-7473)
sum
(clojure.core/let [x (clojure.core/aget
(int-array [1 2 3])
x-i-7472)]
(recur
(clojure.core/unchecked-inc-int x-i-7472)
(. clojure.lang.Numbers (add sum x)))))))]
(if (clojure.core/instance? dom_top.core.Return res-7471)
(.value res-7471)
res-7471))
You can see that the int-array
form will be evaluated multiple times.
Currently I'm using net.cgrand.xforms/for
for it, but feels like it has a bit more overhead than loopr
would if it had support for those for
sugary bits.
A slightly changed example from the docstring as a brief illustration.
(loopr [count 0
sum 0]
[f (range 10)
:when (even? f)
row [[1 2 3] [4 5 6] [7 8 9]]
:let [column (mapv inc row)]
x row
y column]
(recur (inc count) (+ sum (* f x y)))
(/ sum count))
Hey, thanks for a lot for this library. I find the letr
and loopr
not only useful in clj, but also in cljs. It improves the readability of some code quite a bit. Would you be willing to accept a PR for adding cljs support?
I think it would basically involves these changes:
src/core.clj
file able to generate cljs-specific code, e.g. IllegalArgumentException
for clj and js/Error
for cljs. Also the :via :iterator
specific code could use the js Symbol.Iterator
protocol.test/core.clj
file into .cljc format, and use reader conditionals to only execute threadpool related code (bounded-pmap
etc.) in clj.I found a scenario where I'm getting a Nullpointer exception for a certain configuration.
The following works:
(let [deps0 [{:provides #{:a}}
{}]]
(loopr [deps {}]
[current-dep deps0
k (:provides current-dep)]
(recur (assoc deps k current-dep)))) ;=> {:a {:provides #{:a}}}
Adapting the above with one extra accumulator arg2
now throws.
(let [deps0 [{:provides #{:a}}
{}]]
(loopr [deps {}
arg2 {}]
[current-dep deps0
k (:provides current-dep)]
(recur (assoc deps k current-dep) arg2))) ;=> throws NullPointerException
Adding a default value []
works around this issue:
(let [deps0 [{:provides #{:a}}
{}]]
(loopr [deps {}
arg2 {}]
[current-dep deps0
k (:provides current-dep [])]
(recur (assoc deps k current-dep) arg2))) ;=> [{:a {:provides #{:a}}} {}]
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.