Skip to main content

Diigo Home
Home/ Groups/ clojure-dev
Javier Neira

Be mindful of Clojure's binding - Chas Emerick - Muck and Brass - 1 views

  • Binding is thread-local



    This is super-simple, and it's the first thing that one learns upon encountering binding for the first time

  • (pmap
    • Javier Neira
       
      parallel map (create multiple threads others than actual)
    • Javier Neira
       
      parallel map -creates multiples threads-
  • ...4 more annotations...
  • The problem here is that adder is being invoked in threads other than the thread that is establishing the binding on *foo*; therefore, the value of *foo* within adder is always the default, 5.
  • One of the great things about Clojure is you can "do concurrency" using a variety of easy-to-use primitives (e.g. pmap is absolutely the cat's nuts, in that it's a dead-simple way to almost-transparently parallelize computation over a dataset)
  • things like pmap have so little ceremony that it's easy to forget the basics.
  • Notice that some-fn is now explicitly capturing the bound value of the *foo* var; this ensures that, regardless of when and where or on which thread the lazy seq is materialized, the values it contains are what were bound by the caller of some-fn. This is almost always what you want to have happen.
Javier Neira

Datatypes | Clojure | Assembla - 0 views

  • Overall, deftypes will be better than structmaps for all purposes, especially for defining your own data abstractions.
Javier Neira

Parsing SPARQL in Erlang with a monadic combinatory parser « un rato de sol - La ... - 0 views

  • Nevertheless, my current work is based in another interesting functional language, Erlang.
  • For a moment I had the idea of building a Parsec-like library for Erlang. Fortunately Jeffrey Meunler has already done it: http://www.engr.uconn.edu/~jeffm/Source/Erlang/.
  • arsec clones are also available for other languages like Java, Ruby or Python.
Javier Neira

Daily scala: Groupby - collection processing - 0 views

  • Javier Neira
     
    1. def groupBy[K](f : (A) => K) : Map[K, This]
    Examples:

    1. scala> val groups = (1 to 20).toList groupBy {
    2. | case i if(i<5> "g1"
    3. | case i if(i<10> "g2"
    4. | case i if(i<15> "g3"
    5. | case _ => "g4"
    6. | }
    7. res4: scala.collection.Map[java.lang.String,List[Int]] = Map(g1 -> List(1, 2, 3, 4), g2 -> List(5, 6, 7, 8, 9), g3 -> List(10, 11, 12, 13, 14), g4 -> List(15, 16, 17, 18, 19, 20))
    8.
    9. scala> groups.keySet
    10. res6: scala.collection.Set[java.lang.String] = Set(g1, g2, g3, g4)
    11.
    12. scala> groups("g1")
    13. res7: List[Int] = List(1, 2, 3, 4)
    14.
    15. scala> val mods = (1 to 20).toList groupBy ( _ % 4 )
    16. mods: scala.collection.Map[Int,List[Int]] = Map(1 -> List(1, 5, 9, 13, 17), 2 -> List(2, 6, 10, 14, 18), 3 -> List(3, 7,
    17. 11, 15, 19), 0 -> List(4, 8, 12, 16, 20))
    18.
    19. scala> mods.keySet
    20. res9: scala.collection.Set[Int] = Set(1, 2, 3, 0)
    21.
    22. scala> mods(1)
    23. res11: List[Int] = List(1, 5, 9, 13, 17)
Javier Neira

JavaScript: The World's Most Misunderstood Programming Language - 0 views

Javier Neira

Generalizing -> & ->> - Clojure | Grupos de Google - 0 views

  • Javier Neira
     
    (defmacro -$>
    "Threads the expr through the forms. Inserts x into
    the first form at the position marked by the $ symbol.
    If the second form is not a list then it behaves as ->.
    If there are more forms, inserts the first form into the second
    form at the position marked by the $ symbol, etc."
    ([x form] (if (seq? form)
    (let [split (split-with (partial (complement =) '$)
    form)]
    `(~@(first split) ~x ~@(rest (second split))))
    (list form x)))
    ([x form & more] `(-$> (-$> ~x ~form) ~@more)))
Javier Neira

Paste number 89442: tail-recursive qsort - 0 views

  • Javier Neira
     
    (defn qsort [xs]
    (loop [[part & parts :as work] (list xs), out []]
    (if-not work
    out
    (cond
    (coll? part) (let [[pivot & xs] part, smaller #(< % pivot)]
    (recur (conj parts
    (seq (remove smaller xs))
    pivot
    (seq (filter smaller xs)))
    out))
    (nil? part) (recur parts out)
    part (recur parts (conj out part))))))
1 - 20 of 483 Next › Last »
Showing 20 items per page
Join this group