to bankaccount x : balance : transaction
(isnew ⇒ (:balance)
ᗉbalance ⇒ (ᗉ← ⇒ (⇑:balance) ⇑balance)
☞x ← transaction SELF GLOB MESS.
eq #x #SELF ? () ⇑x) '=> bankaccount '
to stockaccount x : numshares pricepershare : transaction
(isnew ⇒ (☞pricepershare ← 30. ☞numshares ← (:) / pricepershare)
ᗉbalance ⇒ ((ᗉ← ⇒ (☞numshares ← (:) / pricepershare)) !numshares * pricepershare)
ᗉnumshares ⇒ (⇑numshares)
☞x ← transaction SELF GLOB MESS.
eq #x #SELF ⇒ () ⇑x) '=> stockaccount '
to t transaction (ev). t
to transaction x
(:#SELF. :x. :MESS. ☞GLOB ← x.
ᗉdeposit ⇒ (⇑SELF balance ← SELF balance + :)
ᗉwithdraw ⇒ (:x > SELF balance ⇒ (error ☞(insufficient funds))
⇑SELF balance ← SELF balance - x)) '=> transaction '
PUT bankaccount ☞transaction #transaction
PUT stockaccount ☞transaction #transaction
done
☞account1 ← bankaccount 100
account1 balance '=> 100 '
account1 deposit 50 '=> 150 '
account1 withdraw 100 '=> 50 '
account1 withdraw 100 '=> 残高不足エラー '
done '=> エラー画面から復帰 '
account1 balance '=> 50 '
account1 deposit 80 '=> 130 '
account1 withdraw 100 '=> 30 '
☞account2 ← stockaccount 300
account2 balance '=> 300 '
account2 numshares '=> 10'
account2 deposit 60 '=> 360 '
account2 numshares '=> 12 '
account2 withdraw 120 '=> 240'
account2 withdraw 270 '=> 残高不足エラー '
done '=> エラー画面から復帰 '
account2 balance '=> 240 '
account2 deposit 90 '=> 330 '
account2 withdraw 270 '=> 60 '
account2 numshares '=> 2 '
to bankaccount x : balance : transaction
(isnew ? (:balance)
%balance ? (%_ ? (!:balance) !balance)
"x _ transaction SELF GLOB MESS.
eq #x #SELF ? () !x) => bankaccount
to stockaccount x : numshares pricepershare : transaction
(isnew ? ("pricepershare _ 30. "numshares _ (:) / pricepershare)
%balance ? ((%_ ? ("numshares _ (:) / pricepershare)) !numshares * pricepershare)
%numshares ? (!numshares)
"x _ transaction SELF GLOB MESS.
eq #x #SELF ? () !x) => stockaccount
to t transaction (ev). t
to transaction x
(:#SELF. :x. :MESS. "GLOB _ x.
%deposit ? (!SELF balance _ SELF balance + :)
%withdraw ? (:x > SELF balance ? (error "(insufficient funds))
!SELF balance _ SELF balance - x)) =>
PUT bankaccount "transaction #transaction
PUT stockaccount "transaction #transaction
done
"account1 _ bankaccount 100
account1 balance => 100
account1 deposit 50 => 150
account1 withdraw 100 => 50
account1 withdraw 100 => 残高不足エラー
done => エラー表示から復帰
account1 balance => 50
account1 deposit 80 => 130
account1 withdraw 100 => 30
"account2 _ stockaccount 300
account2 balance => 300
account2 numshares => 10
account2 deposit 60 => 360
account2 numshares => 12
account2 withdraw 120 => 240
account2 withdraw 270 => 残高不足エラー
done => エラー画面から復帰
account2 balance => 240
account2 deposit 90 => 330
account2 withdraw 270 => 60
account2 numshares => 20
このページを編集 (4134 bytes)
以下の 1 ページから参照されています。 |
This page has been visited 14 times.