fork download
  1. ""1. Data definition"
  2. | library book1 book2 checkoutAction |
  3.  
  4. "Book objects"
  5. book1 := Dictionary new at: #title put: 'BookA'; at: #available put: true; yourself.
  6. book2 := Dictionary new at: #title put: 'BookB'; at: #available put: true; yourself.
  7.  
  8. "Library collection"
  9. library := OrderedCollection with: book1 with: book2.
  10.  
  11. "Checkout logic"
  12. checkoutAction := [:aLibrary :aTitle |
  13.   | book |
  14.   book := aLibrary detect: [:b | (b at: #title) = aTitle] ifNone: [nil].
  15.   (book notNil and: [book at: #available])
  16.   ifTrue: [
  17.   book at: #available put: false.
  18.   Transcript show: 'Success: ', aTitle, ' checked out.'; cr.]
  19.   ifFalse: [
  20.   Transcript show: 'Failed: ', aTitle, ' not available.'; cr.]
  21. ].
  22.  
  23. "Execution"
  24. checkoutAction value: library value: 'BookA'.
  25. checkoutAction value: library value: 'BookA'.your code goes here"
Success #stdin #stdout 0.01s 8864KB
stdin
Standard input is empty
stdout
Object: nil error: did not understand #definition
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
UndefinedObject(Object)>>doesNotUnderstand: #definition (SysExcept.st:1448)
UndefinedObject>>executeStatements (prog:1)