ã¡ããã©ç¡éç´ æ°åã使ããããªã話ã ã£ãã®ã§ Squeak Smalltalk ã§æãã¦ã¿ã¾ããã日本語版Squeak(Squeak4.2-ja-all-in-one) ãªã©ã®ã¯ã¼ã¯ã¹ãã¼ã¹ã¸ãã¼ã¹ãå¾ãããããã¦é¸æãã¦ãã do itï¼å¼ãè©ä¾¡ãalt/cmd + d ãªã©ï¼ã§ä¸ã®å³ãå¾ããã¾ãã
| primesGen pen dotSize width center isPrimeOrNotGen form | primesGen := Generator on: [:g | | primes next | primes := OrderedCollection withAll: #(2 3 5 7). primes do: [:prime | g value: (next := prime)]. [ [:exit | [ next := next + 2. primes anySatisfy: [:prime | prime * prime > next ifTrue: [exit value]. next isDivisibleBy: prime] ] whileTrue] valueWithExit. g value: (primes add: next) ] repeat]. isPrimeOrNotGen := Generator on: [:g | 1 to: Float infinity do: [:n | primesGen peek = n ifTrue: [primesGen next. g value: true] ifFalse: [g value: false]]]. dotSize := 2. width := 200. center := Display center. pen := Pen new defaultNib: dotSize. pen place: center. pen north; turn: 180. Display fillWhite; restoreAfter: [ 1 to: width do: [:length | 2 timesRepeat: [ pen turn: -90. length timesRepeat: [ isPrimeOrNotGen next ifTrue: [pen down]. pen go: 0; up; go: dotSize]]]. form := Form fromDisplay: (center - (width * dotSize// 2) extent: width asPoint * dotSize + dotSize)]. form asMorph openInHand
ãã£ã¨ããä»åã®ããã«ç©å½¢ã®ãµã¤ãºããããããæ±ºãã¦ãã¾ãã®ã§ããã°ãå¿ è¦ãªç´ æ°ã®æå¤§å¤ã決ã¾ãã®ã§ãçµã¿è¾¼ã¿ã®ç´ æ°çæå¨ï¼Integer class>>#primesUpTo:ï¼ã§ãã¾ã£ããåé¡ããã¾ããã
| pen dotSize width center isPrimeOrNotGen form | width := 200. isPrimeOrNotGen := Generator on: [:g | | primesStream | primesStream := (Integer primesUpTo: width * (width + 1) + 1) readStream. 1 to: Float infinity do: [:n | primesStream peek = n ifTrue: [primesStream next. g value: true] ifFalse: [g value: false]]]. dotSize := 2. center := Display center. pen := Pen new defaultNib: dotSize. pen place: center. pen north; turn: 180. Display fillWhite; restoreAfter: [ 1 to: width do: [:length | 2 timesRepeat: [ pen turn: -90. length timesRepeat: [ isPrimeOrNotGen next ifTrue: [pen down]. pen go: 0; up; go: dotSize]]]. form := Form fromDisplay: (center - (width * dotSize// 2) extent: width asPoint * dotSize + dotSize)]. form asMorph openInHand
