You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
http://clojurescript.org[ClojureScript] is a compiler for Clojure that targets JavaScript. It is designed to emit JavaScript code which is compatible with the advanced compilation mode of the http://code.google.com/closure/[Google Closure] optimizing compiler.
14
+
https://clojurescript.org[ClojureScript] is a compiler for Clojure that targets JavaScript. It is designed to emit JavaScript code which is compatible with the advanced compilation mode of the https://developers.google.com/closure/[Google Closure] optimizing compiler.
Today's systems have to deal with many simultaneous tasks and leverage the power of multi-core CPUs. Doing so with threads can be very difficult due to the complexities of synchronization. Clojure simplifies multi-threaded programming in several ways. Because the core data structures are immutable, they can be shared readily between threads. However, it is often necessary to have state change in a program. Clojure, being a practical language, allows state to change but provides mechanism to ensure that, when it does so, it remains consistent, while alleviating developers from having to avoid conflicts manually using locks etc. The <<xref/../../reference/refs#,software transactional memory system>> (STM), exposed through http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/dosync[dosync], http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/ref[ref], http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/ref-set[ref-set], http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/alter[alter], et al, supports _sharing_ changing state between threads in a _synchronous_ and _coordinated_ manner. The <<xref/../../reference/agents#,agent>> system supports sharing changing state between threads in an _asynchronous_ and _independent_ manner. The <<xref/../../reference/atoms#,atoms>> system supports sharing changing state between threads in a _synchronous_ and _independent_ manner. The <<xref/../../reference/vars#,dynamic var system>>, exposed through <<xref/../../reference/special_forms#def#,def>>, http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/binding[binding], et al, supports isolating changing state within threads.
15
+
Today's systems have to deal with many simultaneous tasks and leverage the power of multi-core CPUs. Doing so with threads can be very difficult due to the complexities of synchronization. Clojure simplifies multi-threaded programming in several ways. Because the core data structures are immutable, they can be shared readily between threads. However, it is often necessary to have state change in a program. Clojure, being a practical language, allows state to change but provides mechanism to ensure that, when it does so, it remains consistent, while alleviating developers from having to avoid conflicts manually using locks etc. The <<xref/../../reference/refs#,software transactional memory system>> (STM), exposed through https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/dosync[dosync], https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/ref[ref], https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/ref-set[ref-set], https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/alter[alter], et al, supports _sharing_ changing state between threads in a _synchronous_ and _coordinated_ manner. The <<xref/../../reference/agents#,agent>> system supports sharing changing state between threads in an _asynchronous_ and _independent_ manner. The <<xref/../../reference/atoms#,atoms>> system supports sharing changing state between threads in a _synchronous_ and _independent_ manner. The <<xref/../../reference/vars#,dynamic var system>>, exposed through <<xref/../../reference/special_forms#def#,def>>, https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/binding[binding], et al, supports isolating changing state within threads.
16
16
17
17
In all cases, Clojure does not replace the Java thread system, rather it works with it. Clojure functions are java.util.concurrent.Callable, therefore they work with the Executor framework etc.
18
18
19
-
Most of this is covered in more detail in the http://www.youtube.com/watch?v=dGVqrGmwOAw[concurrency screencast].
19
+
Most of this is covered in more detail in the https://www.youtube.com/watch?v=dGVqrGmwOAw[concurrency screencast].
20
20
21
-
<<xref/../../reference/refs#,Refs>> are mutable references to objects. They can be http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/ref-set[ref-set] or http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/alter[alter]ed to refer to different objects during transactions, which are delimited by http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/dosync[dosync] blocks. All ref modifications within a transaction happen or none do. Also, reads of refs within a transaction reflect a snapshot of the reference world at a particular point in time, i.e. each transaction is isolated from other transactions. If a conflict occurs between 2 transactions trying to modify the same reference, one of them will be retried. All of this occurs without explicit locking.
21
+
<<xref/../../reference/refs#,Refs>> are mutable references to objects. They can be https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/ref-set[ref-set] or https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/alter[alter]ed to refer to different objects during transactions, which are delimited by https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/dosync[dosync] blocks. All ref modifications within a transaction happen or none do. Also, reads of refs within a transaction reflect a snapshot of the reference world at a particular point in time, i.e. each transaction is isolated from other transactions. If a conflict occurs between 2 transactions trying to modify the same reference, one of them will be retried. All of this occurs without explicit locking.
22
22
23
23
In this example a vector of Refs containing integers is created _(+refs+)_, then a set of threads are set up _(+pool+)_ to run a number of iterations of incrementing every Ref _(+tasks+)_. This creates extreme contention, but yields the correct result. No locks!
24
24
[source,clojure]
@@ -45,7 +45,7 @@ In this example a vector of Refs containing integers is created _(+refs+)_, then
45
45
----
46
46
In typical use refs can refer to Clojure collections, which, being persistent and immutable, efficiently support simultaneous speculative 'modifications' by multiple transactions. Mutable objects should not be put in refs.
47
47
48
-
By default Vars are static, but per-thread bindings for Vars defined with <<xref/../../reference/metadata#,metadata>> mark them as dynamic. <<xref/../../reference/vars#,Dynamic vars>> are also mutable references to objects. They have a (thread-shared) root binding which can be established by <<xref/../../reference/special_forms#def#,def>>, and can be set using _*set!*_, but only if they have been bound to a new storage location thread-locally using http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/binding[binding]. Those bindings and any subsequent modifications to those bindings will only be seen _within_ the thread by code in the dynamic scope of the binding block. Nested bindings obey a stack protocol and unwind as control exits the binding block.
48
+
By default Vars are static, but per-thread bindings for Vars defined with <<xref/../../reference/metadata#,metadata>> mark them as dynamic. <<xref/../../reference/vars#,Dynamic vars>> are also mutable references to objects. They have a (thread-shared) root binding which can be established by <<xref/../../reference/special_forms#def#,def>>, and can be set using _*set!*_, but only if they have been bound to a new storage location thread-locally using https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/binding[binding]. Those bindings and any subsequent modifications to those bindings will only be seen _within_ the thread by code in the dynamic scope of the binding block. Nested bindings obey a stack protocol and unwind as control exits the binding block.
49
49
[source,clojure]
50
50
----
51
51
(def ^:dynamic *v*)
@@ -69,7 +69,7 @@ By default Vars are static, but per-thread bindings for Vars defined with <<xref
69
69
(set! *v* 4)
70
70
-> java.lang.IllegalStateException: Can't change/establish root binding of: *v* with set
71
71
----
72
-
Dynamic vars provide a way to communicate between different points on the call stack without polluting the argument lists and return values of the intervening calls. In addition, dynamic vars support a flavor of context-oriented programming. Because fns defined with http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/defn[defn] are stored in vars, they too can be dynamically rebound:
72
+
Dynamic vars provide a way to communicate between different points on the call stack without polluting the argument lists and return values of the intervening calls. In addition, dynamic vars support a flavor of context-oriented programming. Because fns defined with https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/defn[defn] are stored in vars, they too can be dynamically rebound:
Copy file name to clipboardExpand all lines: content/about/functional_programming.adoc
+6-6Lines changed: 6 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -25,7 +25,7 @@ Clojure is a functional programming language. It provides the tools to avoid mut
25
25
(hello)
26
26
-> "Hello world"
27
27
----
28
-
http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/defn[defn] is a macro that makes defining functions a little simpler.
28
+
https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/defn[defn] is a macro that makes defining functions a little simpler.
29
29
Clojure supports arity overloading in a _single_ function object, self-reference, and variable-arity functions using *&*:
30
30
[source,clojure]
31
31
----
@@ -45,7 +45,7 @@ Clojure supports arity overloading in a _single_ function object, self-reference
45
45
(argcount 1 2 3 4 5)
46
46
-> 5
47
47
----
48
-
You can create local names for values inside a function using http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/let[let]. The scope of any local names is lexical, so a function created in the scope of local names will close over their values:
48
+
You can create local names for values inside a function using https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/let[let]. The scope of any local names is lexical, so a function created in the scope of local names will close over their values:
49
49
[source,clojure]
50
50
----
51
51
(defn make-adder [x]
@@ -55,7 +55,7 @@ You can create local names for values inside a function using http://clojure.git
55
55
(add2 4)
56
56
-> 6
57
57
----
58
-
*Locals created with http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/let[let] are not variables. Once created their values never change!*
58
+
*Locals created with https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/let[let] are not variables. Once created their values never change!*
59
59
60
60
61
61
== Immutable Data Structures
@@ -75,7 +75,7 @@ The easiest way to avoid mutating state is to use immutable <<xref/../../referen
Applications often need to associate attributes and other data about data that is orthogonal to the logical value of the data. Clojure provides direct support for this <<xref/../../reference/metadata#,metadata>>. Symbols, and all of the collections, support a metadata map. It can be accessed with the http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/meta[meta] function. Metadata does _not_ impact equality semantics, nor will metadata be seen in operations on the value of a collection. Metadata can be read, and can be printed.
78
+
Applications often need to associate attributes and other data about data that is orthogonal to the logical value of the data. Clojure provides direct support for this <<xref/../../reference/metadata#,metadata>>. Symbols, and all of the collections, support a metadata map. It can be accessed with the https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/meta[meta] function. Metadata does _not_ impact equality semantics, nor will metadata be seen in operations on the value of a collection. Metadata can be read, and can be printed.
79
79
[source,clojure]
80
80
----
81
81
(def v [1 2 3])
@@ -111,7 +111,7 @@ Many of the Clojure library functions produce and consume seqs _lazily_:
111
111
(take 15 (cycle [1 2 3 4]))
112
112
-> (1 2 3 4 1 2 3 4 1 2 3 4 1 2 3)
113
113
----
114
-
You can define your own lazy seq-producing functions using the http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/lazy-seq[lazy-seq] macro, which takes a body of expressions that will be called on demand to produce a list of 0 or more items. Here's a simplified http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/take[take]:
114
+
You can define your own lazy seq-producing functions using the https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/lazy-seq[lazy-seq] macro, which takes a body of expressions that will be called on demand to produce a list of 0 or more items. Here's a simplified https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/take[take]:
115
115
[source,clojure]
116
116
----
117
117
(defn take [n coll]
@@ -138,4 +138,4 @@ In the absence of mutable local variables, looping and iteration must take a dif
138
138
(my-zipmap [:a :b :c] [1 2 3])
139
139
-> {:b 2, :c 3, :a 1}
140
140
----
141
-
For situations where mutual recursion is called for, recur can't be used. Instead, http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/trampoline[trampoline] may be a good option.
141
+
For situations where mutual recursion is called for, recur can't be used. Instead, https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/trampoline[trampoline] may be a good option.
Clojure is designed to be a hosted language, sharing the JVM type system, GC, threads etc. It compiles all functions to JVM bytecode. Clojure is a great Java library consumer, offering the dot-target-member notation for calls to Java. Class names can be referenced in full, or as non-qualified names after being imported. Clojure supports the dynamic implementation of Java interfaces and classes using http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/reify[reify] and http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/proxy[proxy]:
16
+
Clojure is designed to be a hosted language, sharing the JVM type system, GC, threads etc. It compiles all functions to JVM bytecode. Clojure is a great Java library consumer, offering the dot-target-member notation for calls to Java. Class names can be referenced in full, or as non-qualified names after being imported. Clojure supports the dynamic implementation of Java interfaces and classes using https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/reify[reify] and https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/proxy[proxy]:
Systems that utilize runtime polymorphism are easier to change and extend. Clojure supports polymorphism in several ways:
16
16
17
17
* Most core infrastructure data structures in the Clojure runtime are defined by Java interfaces.
18
-
* Clojure supports the generation of implementations of Java interfaces in Clojure using http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/proxy[proxy] (<<jvm_hosted#,see JVM Hosted>>).
18
+
* Clojure supports the generation of implementations of Java interfaces in Clojure using https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/proxy[proxy] (<<jvm_hosted#,see JVM Hosted>>).
19
19
* The Clojure language supports polymorphism along both class and custom hierarchies with <<xref/../../reference/multimethods#,multimethod>>s.
20
20
* The Clojure language also supports a faster form of polymorphism with <<xref/../../reference/protocols#,protocols>> (but limited only to class polymorphism to take advantage of the JVMs existing capabilities for invocation).
21
21
22
22
Clojure multimethods are a simple yet powerful mechanism for runtime polymorphism that is free of the trappings of OO, types and inheritance. The basic idea behind runtime polymorphism is that a single function designator dispatches to multiple independently-defined function definitions based upon some value of the call. For traditional single-dispatch OO languages that value is the type of the 'receiver' or 'this'. CLOS generic functions extend dispatch value to a composite of the type or value of multiple arguments, and are thus multimethods. Clojure multimethods go further still to allow the dispatch value to be the result of an arbitrary function of the arguments. Clojure does not support implementation inheritance.
23
23
24
-
Multimethods are defined using http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/defmulti[defmulti], which takes the name of the multimethod and the dispatch function. Methods are independently defined using http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/defmethod[defmethod], passing the multimethod name, the dispatch _value_ and the function body.
24
+
Multimethods are defined using https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/defmulti[defmulti], which takes the name of the multimethod and the dispatch function. Methods are independently defined using https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/defmethod[defmethod], passing the multimethod name, the dispatch _value_ and the function body.
25
25
26
26
[source,clojure]
27
27
----
@@ -44,6 +44,6 @@ Multimethods are defined using http://clojure.github.io/clojure/clojure.core-api
44
44
-> :fight
45
45
----
46
46
47
-
Multimethods are in every respect fns, e.g. can be passed to http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/map[map] etc.
47
+
Multimethods are in every respect fns, e.g. can be passed to https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/map[map] etc.
48
48
49
49
Similar to interfaces, Clojure protocols define only function specifications (no implementation) and allow types to implement multiple protocols. Additionally, protocols are open to later dynamic extension for new types. Protocols are limited just to dispatch on class type to take advantage of the native Java performance of polymorphic method calls. For more details, see the <<xref/../../reference/protocols#,protocols>> page.
Copy file name to clipboardExpand all lines: content/about/spec.adoc
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -332,7 +332,7 @@ alternative generators for one or more subpaths of a spec.
332
332
In addition to the destructuring use cases above, you can make calls to ``conform`` or ``valid?`` anywhere you want
333
333
runtime checking, and can make lighter-weight internal-only specs for tests you intend to run in production.
334
334
335
-
Please see the <<xref/../../../guides/spec#,spec Guide>> and http://clojure.github.io/clojure/branch-master/clojure.spec-api.html[API docs] for more examples and usage information.
335
+
Please see the <<xref/../../../guides/spec#,spec Guide>> and https://clojure.github.io/clojure/branch-master/clojure.spec-api.html[API docs] for more examples and usage information.
336
336
337
337
== Glossary
338
338
=== predicates
@@ -374,7 +374,7 @@ These paths are used in ``explain``, ``gen`` overrides and various error reporti
374
374
== Prior Art
375
375
Almost nothing about spec is novel. See all the libraries mentioned above, https://www.w3.org/TR/2014/REC-rdf11-concepts-20140225/[RDF],
376
376
as well as all the work done on various
377
-
contract systems, such as http://docs.racket-lang.org/guide/contracts.html[Racket's contracts].
377
+
contract systems, such as https://docs.racket-lang.org/guide/contracts.html[Racket's contracts].
0 commit comments