I've often wondered if there might not be a better way to write while loops
that output a product, similar to enumeration sum: and count:.

| sum count index |
sum := 0.
count := 0.
index := 1.
[ index := index + 1.
   index isPrime ifTrue: [
      count := count + 1.
      sum := sum + index ].
   count = 64 ] whileFalse.

vs something like

| count sum |
count := 0.
sum := 1 until: [ count = 64 ] sum: [ :index |
   index isPrime
      ifTrue: [
         count := count + 1.
         index ]
      ifFalse: [ 0 ] ].

or

| count sum |
count := 0.
sum := (1 until: [ count = 64 ]) sum: [ :index |
   index isPrime
      ifTrue: [
         count := count + 1.
         index ]
      ifFalse: [ 0 ] ].


On Sun, Jul 13, 2014 at 3:05 PM, Sergi Reyner <[email protected]>
wrote:

> It may have been mentioned already, but number 7 is wrong, is states:
>
> "7. Sum of the first 64 primes"
>
> when it actually is:
>
> "7. Sum of the primes not larger than 64"
>
>
> Cheers,
> Sergi
>
>
> 2014-07-12 17:02 GMT+01:00 Sven Van Caekenberghe <[email protected]>:
>
>
>> On 08 Jul 2014, at 21:53, kilon alios <[email protected]> wrote:
>>
>> > Ruby and Pearl look very ugly to me.
>> >
>> > Programming languages are primarily personal preference.
>> >
>> > Pharo advantages to me at least are far more than live image, its live
>> coding which by the way is different from live image, the IDE tools, the
>> factor that is all Pharo objects even when you do assembly coding inside
>> Pharo , the libraries of course and last but not least the community.
>> >
>> > I could name also thousands more advantages that I have found in the
>> implementation that I really like as well others I don't. Devil , as they
>> say, is in the details. Details are everything , generalisations have
>> little meaning.
>> >
>> > Lovely article Sven , keep them coming. I think Pharo would definitely
>> benefit from a cookbook working as a database where pharo coders can use to
>> find example code the easy way.
>>
>> Thanks, Kilon.
>>
>> > But even articles like this can help a lot, I just wish that there was
>> a Pharo wiki to keep these links and see them buried in Pharo news.
>>
>> Yes, I think we need more/better places to link everything together. A
>> curated reading list maybe.
>>
>> > PS: Sven I am making my own Pharo book called Pharo Universe where I
>> want to put things that are not part of PBE or PFTE which can be find here
>> https://github.com/kilon/Pharo-Universe and here
>> https://ci.inria.fr/pharo-contribution/job/PharoUniverse/ . May I have
>> permission to use your articles as chapters for my book ?  I will fully
>> credit you and link back to your blog posts of course :)
>>
>> I know you are doing a lot of effort with respect to documentation and
>> that is really great and important. I am not sure that copying articles
>> that were not meant to be part of a book or larger whole is a good
>> solution, for either party, it will give too much repetition and not a lot
>> of coherence.
>>
>> > On Tue, Jul 8, 2014 at 10:33 PM, Paul Davidowitz <[email protected]>
>> wrote:
>> > Very nice, except all this could be done in Ruby, also elegantly.
>> > The Smalltalk advantage is the live image, and that's where the focus
>> > should be.
>> >
>> >
>>
>>
>>
>


-- 
Jochen "Jeff" Rick, Ph.D.
http://www.je77.com/
Skype ID: jochenrick

Reply via email to