0
我仍然在Clojure noobot,知道我正在尝试解决涉及大学银行交易场景的问题。Clojure:参考银行交易示例
所以...问题是相当容易的,我必须制定一个解决方案,以信用卡,借记卡和汇款。
我停下来这里:
(def account
(ref 100))
(defn credit [account amount]
"Credit"
(dosync
(alter account + amount)))
(defn debit [account amount]
"Debit"
(dosync
(if (> amount (balance account))
(throw (Exception. "Insuficient Funds"))
(alter account - amount))))
(defn transfer [from to amount]
"Transfer"
(dosync
(if (<= amount (balance from))
(do
(Thread/sleep 10)
(debit from amount)
(credit to amount))
(throw
(Exception. "Insuficient Funds")))))
我认为它硬没什么理解和上面的代码工作。
我应该添加帐户号码,交易,在上述像的各功能的数据和在存储器量和存储的描述:
(defn credit [account description data amount]
"Credit"
(dosync
(alter account + amount)))
我与散列映射,载体和其他东西尝试,但没没有工作。我也试图在本书中找到这个解决方案:Clojure编程O'reilly,但仍然很难实现。
谢谢你的时间,让我知道你是否需要更多的信息。
什么是你的问题完全是一个结构的银行账户? – jmargolisvt
我应该在他们可以工作的方式中添加其他“参数”在每个功能,我已经编辑我的问题上面,是否清楚? – junis087678
不完全。现在你的'credit'函数产生一个单一的值。你想让它产生一系列的价值吗?所以'(信用账户20)'会产生类似'[120'存款'时间戳]'的东西?您是否尝试过使用'assoc-in'?数据应该代表什么? – jmargolisvt