#!/usr/bin/perl
require 'operl.pl';

&defclass ('bag','root');
&defmethod('bag','put',      '$elements{$_[0]}++;');
&defmethod('bag','how_many', '$elements{$_[0]};');
&defmethod('bag','kinds',    'keys(%elements);');
&defmethod('bag','delete', 
	'delete $elements{$_[0]} if --$elements{$_[0]} <= 0;');
&defmethod('bag','has',      'defined($elements{$_[0]})');
&defmethod('bag','size',     'foreach $n (%elements) {$sum += $n;};$sum;');
&defmethod('bag','dump',
    'while (($key, $val) = each %elements) {print "$key = $val\n";}');

1;
