We did this for the deposit
function. Although you could
solve deposit
by using set! and writing a helper that rebuilds the entire list, why go
to all that work? set-structure! is a better choice here.
We did this for the remove-account
function. We wanted to remove an entire account, which would modify the list of accounts overall. set-structure! works only on structs, not on variables (such as a ListOfStruct) in general.
We did this when we used set-account-balance! on an account that was shared by two customers, Mcust and Pcust. Changes made to the account structure using set-account-balance! were visible everywhere.
Say that our two customers, Maria and Phil, break up and no longer want to share the account defined by MPacct. We could change the definition of one of the customers by creating a new customer with set!:
(set! Mcust (make-customer "Maria" 5554321 (make-account 123 200)))This replaces the definition for Mcust with a whole new customer structure (and a whole new account structure). The old definition for Mcust is no longer available.