Code Monkey home page Code Monkey logo

clojurescript-unraveled's Introduction

ClojureScript Unraveled

An open source ClojureScript book. Read an HTML version here.

If you found this book useful, consider sponsoring my work on it.

This books aims to serve as:

  • A comprehensive introduction to the ClojureScript language and its idiomatic usage, assuming no previous experience with Clojure or functional programming;
  • a detailed guide of the ClojureScript compiler and the tooling around it; and
  • a mixed bag of topics that are useful in day-to-day ClojureScript programming.

As such, it is divided into three main sections: Language, Tooling & Compiler, and Mixed Bag.

How to Contribute

This is a quick and dirty FAQ:

  • If you found some typo or wording improvements (that do not imply any structural changes) open a pull-request directly.
  • If you want to propose a new chapter, please open an issue for discussing it.
  • If you want to propose a structural change, please open an issue for discussing it.
  • If you want to suggest an additional topic, please open an issue for discussing it.

Please, maintain the commit size small for easy commits picking.

Rules for text formatting:

  • Use correct asciidoctor syntax.
  • Max line width should be 84 chars.

General note:

At this moment, we do not have plans to accept new chapters until the the basic book structure is finished. This is not because we don't want to, but because it's very difficult to handle that at this stage of the book. That being said, proposals are very welcome.

How to build

The book is written using asciidoctor, so you should install the last version of asciidoctor using your package manager. The asciidoctor is responsible of the generation of the online html format. So if you are happy with a local copy in html format, this is a unique dependency that you need.

This is a command for generate the html:

make html
chromium dist/index.html

PDF (Linux)

If you want to generate a pdf. Some additional depencies are needed. For this process we are using fopub tool (included in the repo) that requires the JDK 7 or 8.

For generate pdf, having jdk installed, execute this:

make git
make pdf
# This will generate dist/clojurescript-unraveled.pdf

And finally, if you want to generate epub or mobi, you should install calibre and docbook-xsl using the package manager of you distribution. Once you have this installed, execute the following commands:

make epub
make mobi

PDF (OS X)

In order to build the pdf on OS X, please follow the notes on this issue.

License

This book is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

clojurescript-unraveled's People

Contributors

anler avatar bowd avatar customcommander avatar davidpham87 avatar dottedmag avatar dsevilla avatar iamjarvo avatar jasoncourcoux avatar jdeisenberg avatar jhchabran avatar julianbonilla avatar kostspielig avatar maraujop avatar marcelopereirascmspain avatar martinklepsch avatar mishelashala avatar niwinz avatar o-i avatar oemmerson avatar paasar avatar sandyandi avatar shaunlebron avatar spencercrissman avatar stephenwakely avatar t-gebauer avatar tiensonqin avatar tyler-anderson avatar ul avatar wenxin-wang avatar ykomatsu 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

clojurescript-unraveled's Issues

Namespaced maps section

The cljs compiler now allows use of namespaced maps syntax. This should be reflected in the doc.

About translation

Hi.

Would it be possible to translate clojurescript-unraveled into Japanese? I started learning Clojure(Script) and this document is the best for beginners like me.

I read the License and it seems that I need to keep the original English as it is so that I'll publish it online. So I'd like to add Japanese translation bellow the original English sentences like this:
https://t-cool.github.io/clojurescript-unraveled
I won't claim copyright for my Japanese translation.
I'd appreciate your understanding.

make pdf on OSX howto

For any OSX user with outdated system ruby gem + X11:

brew install ruby
which gem # /usr/local/bin/gem
gem -v # 2.6.2. in my case
(sudo) gem install asciidoctor
which asciidoctor # returned binary path
make git # no errors
make pdf # warnings, and X11 install popup

good god, X11 again:

brew install Caskroom/cask/xquartz # completes without error
make pdf # completes without errors, though pops up invisible java thingy
open -a Preview dist/clojurescript-unraveled.pdf

Awesome!

Problem running on node under Ubuntu

Hi - reading section 4.1.3 I am trying to run under Node.js and get an error. It appears that references to the google closure compiler libs are not being included correctly(?). Output:

~/work/clojurescript-unraveled/myapp > cat src/myapp/core.cljs 
(ns myapp.core
  (:require [cljs.nodejs :as nodejs] ))

(nodejs/enable-util-print!)

(defn -main  [& args]
  (println "Hello world!"))

(set! *main-cli-fn* -main)

~/work/clojurescript-unraveled/myapp > cat build.clj
(require '[cljs.build.api :as b] )

(b/build "src"    {:main          'myapp.core
                   :output-to     "main.js"
                   :output-dir    "out"
                   :target        ":nodejs"
                   :verbose       true } )

~/work/clojurescript-unraveled/myapp > java -cp cljs.jar:src clojure.main build.clj
~/work/clojurescript-unraveled/myapp > java -version
java version "1.8.0_72"
Java(TM) SE Runtime Environment (build 1.8.0_72-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.72-b15, mixed mode)
~/work/clojurescript-unraveled/myapp > node --version
v5.4.1
~/work/clojurescript-unraveled/myapp > 
~/work/clojurescript-unraveled/myapp > d *
-rw-rw-r-- 1 alan alan      254 Apr  2 19:26 build.clj
-rw-rw-r-- 1 alan alan 20078770 Apr  2 19:30 cljs.jar
-rw-rw-r-- 1 alan alan      430 Apr  2 19:45 main.js
drwxrwxr-x 5 alan alan     4096 Apr  2 19:33 out/
drwxrwxr-x 3 alan alan     4096 Apr  2 19:23 src/
~/work/clojurescript-unraveled/myapp > node main.js
/home/alan/work/clojurescript-unraveled/myapp/main.js:2
if(typeof goog == "undefined") document.write('<script src="out/goog/base.js"></script>');
                               ^

ReferenceError: document is not defined
    at Object.<anonymous> (/home/alan/work/clojurescript-unraveled/myapp/main.js:2:32)
    at Module._compile (module.js:397:26)
    at Object.Module._extensions..js (module.js:404:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:429:10)
    at startup (node.js:139:18)
    at node.js:999:3
~/work/clojurescript-unraveled/myapp > 

Building on macOS Mojave

Just wanted to share how I got the HTML to build on macOS Mojave 10.4.5.

Dependencies:

Then use make html. To get the HTML to look right I had to move dist/index.html to the root of the git checkout and then open it (so ./assets/* and ./images/* could be found by the browser).

(NOTE: It might pay for the Makefile to copy ./assets and ./images into ./dist for the html target.)

make pdf on OSX

I followed the steps here:
#134

$ make pdf
mkdir -p docs/
asciidoctor -b docbook45 -a numbered -d book -a data-uri!  src/index.adoc -o docs/clojurescript-unraveled.xml
asciidoctor: FAILED: missing converter for backend 'docbook45'. Processing aborted.
  Use --trace for backtrace
make: *** [docbook] Error 1

I made a search on 'docbook45' and found this repo:
https://github.com/asciidoctor/asciidoctor-backends/tree/master/haml/docbook45

Could anyone advice me how to fix this issue?
I'd appreciate your help.

Better explanation of side effects

I disagree with this statement:

3.7.2. Blocks [...]
A side effect is something that is not necessary for the return value.

  1. Some side effects might also affect the return value. The return value might change depending on some external state.
  2. A side effect should be observable from the outside of the function scope.
(do
  (println "something")    ; this is a side effect
  (- 1 2)                  ; this isn't
  (+ 3 4))

Core ClojureScript protocols

Since CLJS is built on top of protocols, would it make sense to have a section (maybe in "Mixed bag") with the core protocol reference? That would include it's name, functions and examples of implementations and usage.

bootstrapped REPL integration

I've just made a (hopfully) portable bootstrapped REPL w/ auto-complete, auto-documentation, and parinfer, and I'm looking for places that might benefit from a REPL :D

this book is frequently recommended, and I imagine it would be a big value add to have a repl side-by-side w/ the text, especially if you could click a code sample & eval it right there.

I'd be happy to work on integration, but I thought I'd first ask if there's interest

4.6.1 -> :asset-path Required

The following Clojure code:

(assoc build-opts
                  :main 'leapyears.test.main
                  :output-to "out/tests.js"
                  :output-dir "out/tests"
                  :target :nodejs)

needs to be:

(assoc build-opts
                  :main 'leapyears.test.main
                  :output-to "out/tests.js"
                  :output-dir "out/tests"
                  :asset-path "out/tests"
                  :target :nodejs)

and the following Clojure code:

(assoc build-opts
                      :main 'leapyears.test.main
                      :watch-fn run-tests
                      :output-to "out/tests.js"
                      :output-dir "out/tests"
                      :target :nodejs)

needs to be:

(assoc build-opts
                      :main 'leapyears.test.main
                      :watch-fn run-tests
                      :output-to "out/tests.js"
                      :output-dir "out/tests"
                      :asset-path "out/tests"
                      :target :nodejs)

Setting up a ClojureScript development environment - Visual Studio Code

I am trying to lower the thresholds of setting up a Clojurescript development environment with an extension to VS Code I call Calva. I could write a first version of an Appendix B section about Calva, if you like. It's pretty easy with Calva, since it is mainly about installing the extension and, in case of shadow-cljs include a dependency on cider/nrepl. Similar to this: https://shadow-cljs.github.io/docs/UsersGuide.html#_calva_vs_code

Let me know if you want me to issue a PR.

ClojureScript types and records should not be `:import`ed

According to the Clojurescript wiki at https://github.com/clojure/clojurescript/wiki/Differences-from-Clojure#namespaces

:import is available for importing Google Closure classes
ClojureScript types and records should be brought in with :use or :require :refer, not :imported

The book incorrectly says otherwise at http://funcool.github.io/clojurescript-unraveled/#deftype

The types in ClojureScript should be imported with the :import directive of the ns macro

Macros

I think we should have a section on macros but not sure where, talking about them before introducing the compiler tooling might be confusing since they have to be written in Clojure.

4.5 -> tools.clj

I needed to ad the following line of text to the tools.clj file, in addition to the ones noted in the document:

(require '[figwheel.main :as figwheel])

More explicit instructions about file locations and project structure: Chapter 4 Getting started with compiler

The target audience will need more hand holding on setting up that first project.
In Chapter 4: Getting Started with Compiler, there are no explicit instructions on where to put cljs.jar or build.clj.
Having seen linengen projects, I might guess that these go above src (or at least build.clj might) but it's not obvious. We probably want a little graphic or tree-chart showing where each file goes and probably a sidebar about project structure.

Also, capitalize Compiler in the section title.

Any updates on leanpub?

Hi,

Any updates on the Leanpub page of the book?

This book is 75% complete
Updated 9 months Ago 

Thank you.

no println in online REPL

The use of http://www.clojurescript.io/ is recommended, which is great. But many examples in the first tutorial contain the println function, which does not work on this site.

Is there a way to get println working, and should this be mentioned somewhere in the book?

Clarification on Associative Destructuring example

With regards to:

(let [{tenth 10} (range 100)]
  tenth)
;; => 11

Maybe it should be clarified that this is equivalent to:

(get (apply hash-map (range 100)) 10)
;; => 11

and NOT equivalent to:

(get (vec (range 100)) 10)
;; => 10

Core.async's put! returns true if accepted

Hi! In the first example of the core.async section the code shows the following:

(put! ch 42)
;; Got a value: 42
;; => 42

Note that put! returned the value that was just put to the channel.

Just running the example in the REPL the put! returns true instead of 42.

The reader

I think it would be great to explain Lisp machinery such as the reader. Not only Lisp syntax but how Lisp programs are read and what benefits it has (e.g. reader extensions with tagged literals).

Mention cljs.main

Hello! Quickly went through the 2nd edition, it's great, thank you! IMO It would be valuable for readers to know about cljs.main, perhaps a couple of sentences with an example would be enough. WDYT?

Working with third party javascript libraries section

An brief introduction to how to work with third party javascript libraries, how to include it in you application, treat with different javascript module systems and how to package a library that uses javascript libraries.

4.6.1 -> Incorrect namespace reference

The following code:

(ns leapyears.test.main
  (:require [cljs.test :as t]
            [leapyears.vendor.util-closure :as util]))

should be:

(ns leapyears.test.main
  (:require [cljs.test :as t]
            [leapyears.util :as util]))

Expand discussion of map and reduce

I think the book needs at least one more example for both map and reduce that shows a user-defined function. (The problem here is that you know too much--you know that the higher-order-function can be user defined, but the beginner doesn't.) I'll be happy to add the examples and the wording.

Section 4.4.2 -> Function on-change

In order to create what I believe to be the intended behavior I needed to make the definition of the "on-change" function the following:

(defn on-change
  [event]
  (let [target (.-target event)
        value-string (.-value target)]
    (if (str/blank? value-string)
      (set! (.-innerHTML result) "----")
      (let [value (read-string value-string)]
        (if (leap? value)
          (set! (.-innerHTML result) "YES")
          (set! (.-innerHTML result) "NO"))))))

How does clojurescript work with a browser

I'm interested in clojure+clojurescript. The book so far is interesting, but it doesn't bridge the key gap of "how do I, as someone who doesn't currently do browser-based development in another language, approach clojurescript in the browser to accomplish a task".

In a CLI world, I can take a language and know where my inputs and outputs are (files, sockets, apis etc.). What does one do with clojurescript in order to understand the inputs and outputs from the browser, and how does someone learning clojurescript bootstrap themselves into more knowledge? E.g. in order to use D3.js, how would you know where data is coming from, how it is transformed in cljs, and how it could be displayed? This sort of knowledge all seems to be a huge haze of "well, it depends" and having a treatment of this topic seems to be something that would get clojurescript a lot more use.

Minor error in the leap year example

In the current online version, It seems that the leap? predicate has wrong definition. According to wikipedia:

if (year is not divisible by 4) then (it is a common year)
else if (year is not divisible by 100) then (it is a leap year)
else if (year is not divisible by 400) then (it is a common year)
else (it is a leap year)

So leap? may be defined as

(defn leap?
  [year]
  (or (zero? (js-mod year 400))
      (and (pos? (js-mod year 100))
           (zero? (js-mod year 4)))))

Hope I didn't make a mistake.

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.