REBOL [] money-bag: context [ data: copy [] insert: func [value [money!] /local found] [ repeat i length? data [ if (first value) = (first data/:i) [ poke data i add data/:i value found: true break ] ] if not found [append data value] ] remove: func [value [money!] /local found] [ repeat i length? data [ if (first value) = (first data/:i) [ poke data i subtract data/:i value found: true break ] ] if not found [alert "That denomination wasn't found in the bag"] ] ; no conversions yet. total: has [result] [ result: 0 foreach value data [result: result + second value] result ] show: does [probe data] ] ins: func [val] [bag/insert val bag/show] rem: func [val] [bag/remove val bag/show] bag: make money-bag [] ins $100 ins USD$100 ins DEM$100 ins USD$200 rem $50 print bag/total halt
You need to create an account or log in to post comments to this site.