Some Rosetta examples

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Some Rosetta examples

Nicolas Cellier
Hi all,
from time to time, we might want to add some Rosetta snippets for our favourite Smalltalk flavor.

This is related to the discussion having taken place here about Generator(s), timesCollect: ...
I have used Xtreams for laziness capability.
It's not perfect, because the block read stream does not have absolute positioning capability.
I could have used a Generator, if only it had the capability to skip a batch of items...

The snippet is reasonably fast.

One of the pitfalls is the syntax for declaring classes and methods (bangs gives a wrong idea of what Smalltalk coding is).
I guess that's one of the reasons motivating Pharo's Tonel format (like the gnu format)


Reply | Threaded
Open this post in threaded view
|

Re: Some Rosetta examples

timrowledge


> On 2020-04-22, at 2:44 PM, Nicolas Cellier <[hidden email]> wrote:
>
> Hi all,
> from time to time, we might want to add some Rosetta snippets for our favourite Smalltalk flavor.

You might like to also add the fibonacci calculating stuff we had such fun with last year (or was it a century or two ago? Hard to tell these days..)

Web-browser version with the unix #! line removed attached  -


Run with
squeak my.image WebFib.st
and then open browser on http://thatmachine.local:9999/fib/{some number}


tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
Strange OpCodes: IXM: Initiate X-rated error Messages





WebFib.st (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Some Rosetta examples

timrowledge
Dang, I should have mentioned that the current Smalltalk code at https://rosettacode.org/wiki/Fibonacci_sequence#Smalltalk is really, really  ugly and looks like a bad transcription of some C code or similar

tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
Strange OpCodes: MTP: MounT Programmer



Reply | Threaded
Open this post in threaded view
|

Re: Some Rosetta examples

Nicolas Cellier
Once again, I have used a scripting style rather than an object oriented one, which is not completely satisfactory.
IOW, I did it without class but I hope not completely without style...
If some want to complete with a more OO style, welcome!

Le jeu. 23 avr. 2020 à 00:21, tim Rowledge <[hidden email]> a écrit :
Dang, I should have mentioned that the current Smalltalk code at https://rosettacode.org/wiki/Fibonacci_sequence#Smalltalk is really, really  ugly and looks like a bad transcription of some C code or similar

tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
Strange OpCodes: MTP: MounT Programmer





Reply | Threaded
Open this post in threaded view
|

Re: Some Rosetta examples

marcel.taeumel
In reply to this post by Nicolas Cellier
Hi Nicolas.

from time to time, we might want to add some Rosetta snippets for our favourite Smalltalk flavor.

Absolutely. :-) Is there a place for this:

input := #( (1 2 3) (a b) (nil) ).
output := input inject: #(()) into: [:a :b | (a collect: [:i | b collect: [:j | i copyWith: j]]) reduce: #,].
"#(#(1 #a nil) #(1 #b nil) #(2 #a nil) #(2 #b nil) #(3 #a nil) #(3 #b nil))"

One of the pitfalls is the syntax for declaring classes and methods

Reminds me of Christoph's recent DynamicObject proposal. What about this:

Class named: #SomeNewClass vars: #(a b c) withAll: {
   #foo -> [:inst | 12 + inst baz].
   #bar: -> [:inst :arg | arg + 12].
   #baz -> [:inst | inst a].
}

... with auto-generated accessors.

Best,
Marcel

Am 22.04.2020 23:45:54 schrieb Nicolas Cellier <[hidden email]>:

Hi all,
from time to time, we might want to add some Rosetta snippets for our favourite Smalltalk flavor.

This is related to the discussion having taken place here about Generator(s), timesCollect: ...
I have used Xtreams for laziness capability.
It's not perfect, because the block read stream does not have absolute positioning capability.
I could have used a Generator, if only it had the capability to skip a batch of items...

The snippet is reasonably fast.

One of the pitfalls is the syntax for declaring classes and methods (bangs gives a wrong idea of what Smalltalk coding is).
I guess that's one of the reasons motivating Pharo's Tonel format (like the gnu format)