home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Interactive Guide
/
c-cplusplus-interactive-guide.iso
/
c_ref
/
csource4
/
231_01
/
primes.st
< prev
next >
Wrap
Text File
|
1987-06-17
|
768b
|
37 lines
Class Main
[
main
(Primes new) do: [:x | x print]
]
Class Primes
| primeGenerator lastFactor |
[
first
primeGenerator <- 2 to: 300.
lastFactor <- primeGenerator first.
^ lastFactor
|
next
primeGenerator <- (Factor new ;
remove: lastFactor
from: primeGenerator ).
^ lastFactor <- primeGenerator next.
]
Class Factor
| myFactor generator |
[
remove: factorValue from: generatorValue
myFactor <- factorValue.
generator <- generatorValue
|
next | possible |
[(possible <- generator next) notNil]
whileTrue:
[(possible \\ myFactor ~= 0)
ifTrue: [ ^ possible] ].
^ nil
]