What is the difference between using swap!
and reset!
in Clojure functions? I have seen from the clojure.core docs that they are used to change the value of an atom but I am not sure when to use swap!
and when to use reset!
.
What circumstances would you use swap!
and which circumstances would you use reset!
?
[:input {:type "text"
:value @time-color
:on-change #(reset! time-color (-> % .-target .-value))}]
The above code is an example of using reset!
for a button
[:input.form-control
{:type :text
:name :ric
:on-change #(swap! fields assoc :ric (-> % .-target .-value))
:value (:ric @fields)}]
And this button uses swap!
Are swap!
and reset!
interchangeable?
Thanks
In an interest rate swap, the only things that actually get swapped are the interest payments. An interest rate swap, as previously noted, is a derivative contract.
Use a Swaption: A swaption is an option on a swap. Purchasing a swaption would allow a party to set up, but not enter into, a potentially offsetting swap at the time they execute the original swap. This would reduce some of the market risks associated with Strategy 2.
The motivations for using swap contracts fall into two basic categories: commercial needs and comparative advantage. The normal business operations of some firms lead to certain types of interest rate or currency exposures that swaps can alleviate.
Usually, the swap reset date precedes the payment date by the number of months in a reset period (three months, six months, etc). Occasionally, it happens that swaps trade on interim dates that do not correspond to calendar dates (swap reset dates and payment dates) that are set by market convention.
swap!
uses a function to modify the value of the atom. You will usually use swap!
when the current value of the atom matters. For example, incrementing a value depends on the current value, so you would use the inc
function.
reset!
simply sets the value of the atom to some new value. You will usually use this when you just want to set the value without caring what the current value is.
(def x (atom 0))
(swap! x inc) ; @x is now 1
(reset! x 100) ; @x is now 100
(swap! x inc) ; @x is now 101
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With