QUESTION 3 (18 MARKS) Given the following code snippet to transfer the funds from account1 to account2. 1. 2. 3. 4. 5. 6
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
QUESTION 3 (18 MARKS) Given the following code snippet to transfer the funds from account1 to account2. 1. 2. 3. 4. 5. 6
QUESTION 3 (18 MARKS) Given the following code snippet to transfer the funds from account1 to account2. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. (def accountl (atom 0:validator # (>= 8 0))) (def account2 (atom 0 :validator # (>= % 0) ) ) (defn transfer [from-acct to-acct amt] (swap! to-acct + amt) (swap! from-acct - amt)) (future (transfer account1 account2 100)) (println (str "accountl: "@account1)) (println (str "account2: " @account2)) Determine the output of the given code and justify your answer. (5 markah/marks) Use Ref Clojure function instead of the atom in the given code and justify the reason of why Ref is more effective than the atom. (13 markah/marks)