[self-interest] [Ann] A simple streaming framework
mail at russell-allen.com
Wed Jun 15 23:01:30 UTC 2016
> On 16 Jun 2016, at 7:08 AM, 'Jecel Assumpcao Jr.' jecel at merlintec.com [self-interest] <self-interest at yahoogroups.com> wrote:
> you might find the stream framework that Craig Latta created for
> Smalltalk (also called "Flow" - great minds think alike)
Ha. Probably only so many watery metaphors out there :) I’ll have a look
> In the book "Little Smalltalk", Tim Budd mentions that his generators
> were composable unlike Smalltalk-80's streams
> > http://sdmeta.gforge.inria.fr/FreeBooks/LittleSmalltalk/ALittleSmalltalk.pdf <http://sdmeta.gforge.inria.fr/FreeBooks/LittleSmalltalk/ALittleSmalltalk.pdf>
> Chapter 8 explains that generators use the protocol #first and #next.
> Streams use #next and #atEnd instead, but they can have nil as an
> element while generators can’t.
interesting. What to do with the end of streams seems a common point of variance.
Smalltalk-80 uses ‘atEnd’, which doesn’t work if the only way you can find out if you are at the end is to read and fail (such as a socket).
The newer system Xtreams as far as I can tell uses exceptions which Self doesn’t have.
>From what you say Little Smalltalk uses nil, which means you can’t put nil in your streams.
I considered a specific EndOfStream object, and in the end chose to go with the common Self pattern of passing in error handlers, i.e.
stream readIfFail: [|:e| do something with e] and
stream write: obj IfFail: [|:e| what went wrong? ]
The other main differences with my flow I think is the plugging together of streams and filters is done more explicitly. e.g. compare this in xtreams:
String new writing
write: 5 from: ’Hello World’ reading; conclusion.
with the flow equivalent:
((‘Hello World’ reading |= ‘' writing) pulIUpTo: 5) contents
First you build your pipeline, then you make it do work, then you convert your result into something non-stream.
Of course it would be even nicer if we had a proper cascade operator like Tim Budd put in Little Smalltalk (which was an improvement over Smalltalk-80’s use of $;), then we could say:
'Hello World’ reading |= ‘’ writing; pulIUpTo: 5; contents
Oh well, add it to the Yak shaving list.
This starts off looking really nice then seems to become quite complex!
> -- Jecel
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Self-interest