I understand the words, but I don't conceptually get the purpose / meaning of these. When should I / how can I know when to use them?
Best Answer
Use Refs for synchronous, coordinated and shared changes.
Use Agents for asynchronous, independent and shared changes.
Use Atoms for synchronous, independent and shared changes.
Use Vars for isolated changes.
EDIT
The links you posted are highly important to read, however I also recommends this: Software Transactional Memory
Keep in mind that aborted transactions will be replayed. What does this mean?
It means that the code inside dosync could be executed a couple of times, so you need to be careful the code should be side effects free.
One use of agents is to have a controlled side effects. Consider this:
The STM will hold all of the actions needed to be sent to agents until succeed.
What is difference between atoms and agents?
Updates to agents will happen asynchronously at some point of the future, updates to atoms will happened immediately.
Atoms and agents don't need to run inside a transaction, refs should be (coordinated changes, remember?)
We argue against call/cc as a core language feature, as the distinguished control operation to implement natively relegating all others to libraries. The primitive call/cc is a bad abstraction -- in various meanings of 'bad' shown below, -- and its capture of the continuation of the whole program is not practically useful. The only reward for the hard work to capture the whole continuation efficiently is more hard work to get around the capture of the whole continuation. Both the users and the implementors are better served with a set of well-chosen control primitives of various degrees of generality with well thought-out interactions...
...Offering call/cc as a core control feature in terms of which all other control facilities should be implemented turns out a bad idea. Performance, memory and resource leaks, ease of implementation, ease of use, ease of reasoning all argue against call/cc. If there is really one distinguished control feature to implement as a primitive, with others relegated into libraries, it is not call/cc.
the & in (defn full-name [& {first :first last :last}] indicates that all the remaining arguments should be gathered into a single collection. the map destructuring form following the & then takes the map created by the & apart again.
for your other question: symbols and keywords implement the function interface so they can be called just like any other Clojure function. when called as a function they look themselves up in their argument which they expect to be a map (or something implementing the appropriate interface)
Best Answer
EDIT
The links you posted are highly important to read, however I also recommends this: Software Transactional Memory
Keep in mind that aborted transactions will be replayed. What does this mean?
It means that the code inside dosync could be executed a couple of times, so you need to be careful the code should be side effects free.
One use of agents is to have a controlled side effects. Consider this:
The STM will hold all of the actions needed to be sent to agents until succeed.
What is difference between atoms and agents?
Updates to agents will happen asynchronously at some point of the future, updates to atoms will happened immediately.
Atoms and agents don't need to run inside a transaction, refs should be (coordinated changes, remember?)