ObjectSieve.borg
ObjectSieve.borg
{
`creeert zeef-objecten
`illustrates how the behavior of an object can be changed
`the data method it's behavior changes to check the prime
`after the arrival of the first unknown number
createsieve(next,collector)::
{
prime:0;
data(num):
{collector.prime(prime:=num);
data:=checker};
checker(num):
if( (!((num\\prime)=0)), next.data(num));
clone()
};
`start de zeef met 500 filters
startsieve()::
{
numcounter:0;
prime(p)::
{if ((numcounter\\10)=0,display(eoln));
display(" "+text(p));
numcounter:=numcounter+1};
data(p)::void;
col:beg:clone();
for(i:547,i>0,i:=i-1, beg:=createsieve(beg,col));
for(i:2,i<547,i:=i+1, beg.data(i));
eoln
};
display("startsieve()")
}