home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / language / quinta.cpt / Quinta / sieve.q < prev   
Encoding:
Text File  |  1990-03-27  |  1.7 KB  |  49 lines

  1. ; This is the source for a Sieve program in Quinta
  2.  
  3. ; Four new classes: item,counter,filter, and sieve
  4. ; The message out is defined for all objects of class item
  5. ; But it is assumed that all subclasses of item will
  6. ; redefine it.  Thus item out is a "null" response
  7. ;
  8. ; This program was converted from an example program in C++
  9. ; from the book "Programming Languages: Concepts and Constructs"
  10. ; by Ravi Sethi.  In my Programming Languages course, one of
  11. ; our assignments was to convert this algorithm to Smalltalk.
  12. ; Presented here, it has the full functionality of the original
  13. ; and is an excellent example of object oriented program design.
  14. ; In addition, it nicely illustrates the builder responses of
  15. ; Quinta.
  16. ;
  17. ; The user interface to this program is the message sieve_p.
  18. ; It is defined for class integer and the integer argument is
  19. ; the number of primes to be found
  20. ;
  21.  ; ---------------------------------------------------------
  22. "source" 1 >list nl "item" generic subclass
  23. [ 'source' sto ] item setbld
  24.  
  25. nl "value" 1 >list "counter" item subclass
  26. [ 'value' sto 1 swap item bld ] counter setbld
  27.  
  28. "factor" 1 >list nl "filter" item subclass
  29. [ 'factor' sto item bld ] filter setbld
  30.  
  31. nl dup "sieve" item subclass
  32. [ item bld ] sieve setbld
  33.  
  34. [ 0 ] "out" pub item respond
  35.  
  36. [ dup value swap over 1 + swap 'value' sto ] "out" pub counter respond
  37.  
  38. [ 0 do drop dup source out rot 'source' sto dup rot dup rot
  39. factor mod 0 != until swap ] "out" pub filter respond
  40.  
  41. [ dup source out swap dup rot swap filter new rot item bld ] "out" pub sieve respond
  42.  
  43. [ "manyprimes" local 2 counter new sieve new 0 do swap out rot 1 + dup manyprimes
  44. > until swap drop >list cr ] "sieve_p" pub control respond
  45.  
  46.  ; -----------------------------------------------------------------
  47.  
  48.  
  49.