A Name for Money Objects
This is a concrete design of a money object along the lines proposed in (p3,asset).
A “sum” is an object representing a certain amount of money. The amount is an integer >= 3. Some sums are “dead”.
A sum can produce another sum such that the amounts of the two resulting sums add to the amount of the original sum. A sum can merge with another sum, deleting it, whereupon its amount will be the sum of the original amounts.
SUM(0;==>0,(7,amount);) returns the amount.
SUM(1,(7,na);==>c;NSUM) returns a new un-dead sum, NSUM, of amount na. SUM's amount is decreased by be na.
SUM(kt;==>X'30')
Programming Note:
There are two schemes that come to mind:
Build objects from holder's spacebank.
An <account> has a <balance>, which is a non-negative {unnormalized floating point?} number {probably 64 bits} denominated in dollars {or TRU's, or grams of gold}. An account may also have a reference to an account called the <parent> of the account.
An account is <exhausted> if and only if its balance is zero or it has a parent who is exhausted.
Some keys to accounts “may be used to read the balance”.
Proc withdraw = (Ref Account a, Real amt) Bool: #Withdraws amt from a, returns True iff successful. # (Bool success = If balance Of a < amt Then False Elif parent Of a Is Ref Account(Nil) Then True Else withdraw(parent Of a, amt) Fi; (success ^ balance Of a -:= amt); success);
Proc withdraw and truncate = (Ref Account a, Real amt) Real: # withdraw as much as possible, but no more than amt. Returns amount withdrawn. # (Real w = If Real am = min(balance Of a, amt); parent Of a Is Ref Account(Nil) Then am Else withdraw and truncate(parent Of a, am) Fi; balance Of a -:= w; w);
{Note that these two functions serve to deposit as well as withdraw.}
If t = 0 Then # Transfer amount # If withdraw(payer, pmt) Then (code := 0, actual := pmt) Else (code := 2, actual := 0 ) Fi Elif t = 1 Then # Transfer up to limit # (code := 0, actual := withdraw and truncate(payer, pmt)) Fi; withdraw(payee, -actual))
acnt(5;==>;) Returns when the balance is zero. (Can more than one wait?)
acnt(6,balance;SB==>c;k) “Create account”. A new account k is produced. SB must be an official space bank. This call will be prompt if SB is. The balance of the new account will be “balance” and the parent will be acnt if acnt is an account and there will be no parent otherwise. IF SB is sufficient Then If accnt1 is an account Then c = 0 Else c = 1 Fi Else c = 2 Fi.
acnt(12;==>;) “Destroy”.
Suppose that an individual wanted to introduce an account system into a commercial Gnosis system with no special hooks into Gnosis or the operator of the system. We call this individual the banker.
The banker then publicly offers a service of converting between real dollars and accounts.
On other occasions the holder of an account sends the account to an entry provided by the banker with instructions to make out and mail a check. {This account holder need not previously be known to the banker.} The banker keeps no record of this event.
One awkward solution is to build the account from a central bank and power it with an account supplied by the account system. Shall we say a “bank charge”?
In a typical buying situation, the resource server gives a key to the resource, in exchange for which it makes a one-time charge to an account, which covers the expense of storing forever the information associated with the resource. The resource server may also make a charge to an account for each transaction on the resource. {The account server is an example of such a resource server.} The resource server may provide for turning in (“destroying”) a resource and recovering its scrap value. It should provide for recycling resources even when all keys to the resource have been lost. {The account server provides this by means of the hierarchy of accounts.}
Example. Suppose a user wants to engage in a debugging session and wants to limit the amount spent to about, say, $100. If the debugging session tries to spend more than that, the user wants to be notified and, at that time, make a decision whether to spend more money on the session; but while he is making a decision, he does not want anything to be destroyed. Solution: The user creates a subaccount with a sufficiently large credit limit and deposits $100 in the subaccount's balance. The user creates an independent process (running under the parent account) which executes the call to wait until the subaccount's balance is zero. If and when the balance becomes zero, this process will notify the user. Meanwhile, the nonzero credit limit of the account insures that the account will not become exhausted (assuming the parent has enough money) and therefore no {rented} resources will be invalidated or destroyed. While the user is making his decision, the process could take any non-destructive steps to reduce the charge to the account, such as stopping processes that are running under the account, or moving data to less expensive storage media.
Advantages to Purses
Efficient limited payment.