Giter Site home page Giter Site logo

dom-top's People

Contributors

aphyr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dom-top's Issues

Loopr performance

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

(let [[sum count] (reduce (fn [[count sum] row]

It should be (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

Swap file in src

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! ๐Ÿ˜‰

Multiple evaluation of form with :via :array

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.

Consider increasing the masochism factor by adding support for `:let`/`:while`/`:when` to `loopr`

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))

Do you accept a patch to make this library work for ClojureScript?

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:

  1. make the macros in 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.
  2. make the test/core.clj file into .cljc format, and use reader conditionals to only execute threadpool related code (bounded-pmap etc.) in clj.

Nullpointer exception in particular configuration

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}}} {}]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.