我有一个Pharo扩展,为Pharo Smalltalk增添了许可。然后,我使用承诺延期与以下银行申请进行银行转帐。一个帐户与银行联系,以便将钱转移到另一个帐户。此代码失败,错误为 SubscriptOutOfBounds:5 。我看了Recursive method in pharo produces #SubscriptOutOfBounds:8。它讨论了数组边界,但我不知道我可以在我的实现中使用数组,除非堆栈有效。调试器说了一些关于数组的东西,但目前它对我来说太神秘了。承诺与其他例子一样好用但是这个特定的例子失败了。由于帐户>> transfer:to:
中已注释掉的代码,似乎发生了错误以下是帐户>>转帐:至:
transfer: amount to: account
| bank promise|
bank := Bank new.
(availability > (lowerLimit + amount)) ifTrue: [ availability := availability - amount.
promise := [ bank transfer: amount from: self to: account ]promiseValue.
"promise
then: [ :respose |
respose
ifTrue: [ self reduceBalance: amount ] ]
catch: [ :error | ^error ] "]
ifFalse: [ ^ self ].
这是Bank>>转移:金额:从:到:
transfer: amount from: anAccount1 to: anAccount2
|transfered|
transfered := false.
(anAccount1 availableBalance < anAccount1 lowerLimit + amount)
ifTrue:
[self error: 'Account lower Limit reached', (anAccount1 lowerLimit) printString ]
ifFalse:
[ self deposit: amount to: anAccount2. transfered := true ].
^transfered
导致此错误的原因是什么?