<commit_before>[![Build Status](https://travis-ci.org/Lambda-X/replumb.svg?branch=travis)](https://travis-ci.org/Lambda-X/replumb)

<p>
  <img src="https://raw.githubusercontent.com/ScalaConsultants/replumb/master/images/replumb_logo_bg.jpg" alt="Replumb Logo"/>
</p>

Replumb (*'rɛplʌm*) is a plumbing library for your [self-hosted](https://en.m.wikipedia.org/wiki/Self-hosting_compiler) ClojureScript Read-Eval-Print-Loops. Live demo available at [clojurescript.io](http://clojurescript.io).

This library tries to ease the burden of talking directly to ClojureScript ```cljs.js``` and puts together [pieces](https://github.com/kanaka/cljs-bootstrap) [of](https://github.com/mfikes/planck) [work](https://github.com/mfikes/replete) contributed by the ClojureScript community at disparate points in time on the [`cljs-in-cljs`](https://github.com/clojure/clojurescript/wiki/Bootstrapping-the-Compiler#cljs-in-cljs-from-2012) subject. It aspires to be a common starting point for custom REPLs and/or REPL-ish apps (educational interactive environments for instance).

### Thanks

As [current maintainer](https://github.com/arichiardi) of the project I would like to thank each and every present and future contributor, [Scalac](https://scalac.io) for actively supporting the (Clojure) open source community and [Mikes Fikes](https://github.com/mfikes) for having answered to my incessant questions on Slack, for having aided in brainstorming the project name and of course for the symbiosis with [planck](https://github.com/mfikes/planck).

## Usage

Put the following into the `:dependencies` vector.

[![via Clojars](http://clojars.org/replumb/latest-version.svg)](http://clojars.org/replumb)

After that directly call ```replumb.core``` functions:

``` clojure
(ns ...
  (:require ...
            [replumb.core :as replumb]
            [your.io.impl :as io]))

(defn handle-result!
  [console result]
  (let [write-fn (if (replumb/success? result) console/write-return! console/write-exception!)]
    (write-fn console (replumb/unwrap-result result))))

(defn cljs-read-eval-print!
  [console repl-opts user-input]
  (replumb/read-eval-call repl-opts
                          (partial handle-result! console)
                          user-input))

(defn cljs-console-did-mount
  [console-opts]
  (js/$
   (fn []
     (let [repl-opts (merge (replumb/browser-options ["/src/cljs" "/js/compiled/out"]
                                                     io/fetch-file!)
                            {:warning-as-error true
                             :verbose true})
           jqconsole (console/new-jqconsole "#cljs-console" console-opts)]
       (cljs-console-prompt! jqconsole repl-opts)))))
```

Note that `replumb`, like ClojureScript, abstracts over `IO` details. You will
need to provide your own read/write functions for it to work. There are examples of 
this in the `replumb.browser.io` and `replumb.nodejs.io` that you can freely copy over.

## Read-eval-call options

The core of it all is `read-eval-call`, which reads, evaluates and calls back
with the evaluation result.

The first parameter is a map of configuration options, currently
supporting:

* `:verbose` will enable the the evaluation logging, defaults to false
* `:warning-as-error` will consider a compiler warning as error
* `:target` `:nodejs` and `:browser` supported, the latter is used if
missing
* `:init-fn!` user provided initialization function, it will be passed a
map:

        :form   ;; the form to evaluate, as data
        :ns     ;; the current namespace, as symbol
        :target ;; the current target
<commit_msg>Fix typo in README<commit_after>[![Build Status](https://travis-ci.org/Lambda-X/replumb.svg?branch=travis)](https://travis-ci.org/Lambda-X/replumb)

<p>
  <img src="https://raw.githubusercontent.com/ScalaConsultants/replumb/master/images/replumb_logo_bg.jpg" alt="Replumb Logo"/>
</p>

Replumb (*'rɛplʌm*) is a plumbing library for your [self-hosted](https://en.m.wikipedia.org/wiki/Self-hosting_compiler) ClojureScript Read-Eval-Print-Loops. Live demo available at [clojurescript.io](http://clojurescript.io).

This library tries to ease the burden of talking directly to ClojureScript ```cljs.js``` and puts together [pieces](https://github.com/kanaka/cljs-bootstrap) [of](https://github.com/mfikes/planck) [work](https://github.com/mfikes/replete) contributed by the ClojureScript community at disparate points in time on the [`cljs-in-cljs`](https://github.com/clojure/clojurescript/wiki/Bootstrapping-the-Compiler#cljs-in-cljs-from-2012) subject. It aspires to be a common starting point for custom REPLs and/or REPL-ish apps (educational interactive environments for instance).

### Thanks

As [current maintainer](https://github.com/arichiardi) of the project I would like to thank each and every present and future contributor, [Scalac](https://scalac.io) for actively supporting the (Clojure) open source community and [<NAME>](https://github.com/mfikes) for having answered to my incessant questions on Slack, for having aided in brainstorming the project name and of course for the symbiosis with [planck](https://github.com/mfikes/planck).

## Usage

Put the following into the `:dependencies` vector.

[![via Clojars](http://clojars.org/replumb/latest-version.svg)](http://clojars.org/replumb)

After that directly call ```replumb.core``` functions:

``` clojure
(ns ...
  (:require ...
            [replumb.core :as replumb]
            [your.io.impl :as io]))

(defn handle-result!
  [console result]
  (let [write-fn (if (replumb/success? result) console/write-return! console/write-exception!)]
    (write-fn console (replumb/unwrap-result result))))

(defn cljs-read-eval-print!
  [console repl-opts user-input]
  (replumb/read-eval-call repl-opts
                          (partial handle-result! console)
                          user-input))

(defn cljs-console-did-mount
  [console-opts]
  (js/$
   (fn []
     (let [repl-opts (merge (replumb/browser-options ["/src/cljs" "/js/compiled/out"]
                                                     io/fetch-file!)
                            {:warning-as-error true
                             :verbose true})
           jqconsole (console/new-jqconsole "#cljs-console" console-opts)]
       (cljs-console-prompt! jqconsole repl-opts)))))
```

Note that `replumb`, like ClojureScript, abstracts over `IO` details. You will
need to provide your own read/write functions for it to work. There are examples of 
this in both `replumb.browser.io` and `replumb.nodejs.io` that you can freely copy over.

## Read-eval-call options

The core of it all is `read-eval-call`, which reads, evaluates and calls back
with the evaluation result.

The first parameter is a map of configuration options, currently
supporting:

* `:verbose` will enable the the evaluation logging, defaults to false
* `:warning-as-error` will consider a compiler warning as error
* `:target` `:nodejs` and `:browser` supported, the latter is used if
missing
* `:init-fn!` user provided initialization function, it will be passed a
map:

        :form   ;; the form to evaluate, as data
        :ns     ;; the current namespace, as symbol
        :target ;; the current target

{'fraction_non_alphanumeric': 0.12404817942683095, 'fraction_numerical': 0.001107573030596705, 'mean_word_length': 3.456508328192474, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 24, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3240726', 'n_tokens_mistral': 2245, 'n_tokens_neox': 2191, 'n_words': 664}