concept pcall in category clojure

appears as: pcalls
Clojure: The Essential Reference MEAP V30

This is an excerpt from Manning's book Clojure: The Essential Reference MEAP V30.

  • “pmap, pcalls and pvalues” executes the map operation on a separate thread thus creating a parallel map. Replacing map with “pmap, pcalls and pvalues” makes sense when the overall cost of handling the function f to separate threads is less than the execution of f itself. Long or otherwise processor-consuming operations usually benefit from using “pmap, pcalls and pvalues”.
  • pmap, pcalls and pvalues build a lazy sequence as the result of processing a set of expressions in parallel (using futures). Both pcalls and pvalues build on top of pmap. pmap has a similar interface to map, but transformations apply to the input in parallel:

    (pmap + (range 10) (range 10)) ; #1
    ;; (0 2 4 6 8 10 12 14 16 18)

    pcalls builds on top of pmap accepting any number of functions as input. It then creates a lazy sequence from the results of calling the functions without arguments. pcalls is a good solution for side effecting parallel transformations:

    sitemap

    Unable to load book!

    The book could not be loaded.

    (try again in a couple of minutes)

    manning.com homepage
    test yourself with a liveTest