home *** CD-ROM | disk | FTP | other *** search
- ; This is the source for a Sieve program in Quinta
-
- ; Four new classes: item,counter,filter, and sieve
- ; The message out is defined for all objects of class item
- ; But it is assumed that all subclasses of item will
- ; redefine it. Thus item out is a "null" response
- ;
- ; This program was converted from an example program in C++
- ; from the book "Programming Languages: Concepts and Constructs"
- ; by Ravi Sethi. In my Programming Languages course, one of
- ; our assignments was to convert this algorithm to Smalltalk.
- ; Presented here, it has the full functionality of the original
- ; and is an excellent example of object oriented program design.
- ; In addition, it nicely illustrates the builder responses of
- ; Quinta.
- ;
- ; The user interface to this program is the message sieve_p.
- ; It is defined for class integer and the integer argument is
- ; the number of primes to be found
- ;
- ; ---------------------------------------------------------
- "source" 1 >list nl "item" generic subclass
- [ 'source' sto ] item setbld
-
- nl "value" 1 >list "counter" item subclass
- [ 'value' sto 1 swap item bld ] counter setbld
-
- "factor" 1 >list nl "filter" item subclass
- [ 'factor' sto item bld ] filter setbld
-
- nl dup "sieve" item subclass
- [ item bld ] sieve setbld
-
- [ 0 ] "out" pub item respond
-
- [ dup value swap over 1 + swap 'value' sto ] "out" pub counter respond
-
- [ 0 do drop dup source out rot 'source' sto dup rot dup rot
- factor mod 0 != until swap ] "out" pub filter respond
-
- [ dup source out swap dup rot swap filter new rot item bld ] "out" pub sieve respond
-
- [ "manyprimes" local 2 counter new sieve new 0 do swap out rot 1 + dup manyprimes
- > until swap drop >list cr ] "sieve_p" pub control respond
-
- ; -----------------------------------------------------------------
-
-
-