I am new to Functional Programming and Clojure, so I am not really sure about what to do for a project at University. The project should show the advantage of Clojure STM for banking transactions (Transfer of money from account A to account B). So I plan to proceed this way:
- define initial data, like a matrix of Refs or something better
- generate random operations to execute:
[ random-account-source-id(0, N_MAX) , random-account-destination-id(0, N_MAX), random-money (0, 1000) ]
- insert the transaction into the data structure
- Sync transfer of money from source-id to destination-id for all
the insertions in the matrix, such as:
for i=0; i lt N; i++; synchronize: transfer (matrix[i].source,matrix[i].dest,matrix[i].money)
I'm not sure about this, then, maybe:
(defn do-all[]
(dosync
(when (pos? N)
(transfer (get matrix [pos 1], get matrix [pos 2], get matrix [pos 3])))))