[e-lang] makeStitchPair (was EProxyResolver and ...)

Kevin Reid kpreid at mac.com
Mon Mar 26 09:07:18 CDT 2007


On Mar 25, 2007, at 14:14, Mark S. Miller wrote:
> Kevin Reid wrote:
>> I'm impressed. Even after reading the code, the examples, and  
>> experimenting with it, I still don't know how it does what it  
>> does. :)
>
> Does the following animation help?
> <http://erights.org/elib/concurrency/multi-channel/>

Yes, though not quickly. I now understand the code.

With this knowledge, I say the reason I found it confusing is that  
the "next" variable is used for two completely different purposes  
depending on the value of "head".

It would have been much clearer if this were written out in some  
explicit form. Haskell-style data types come to mind:

data StitchState = Middle { item :: Any; next :: Stitch }
                  | End    { otherStitchEnd :: Stitch }

Or, here's a behavior-switching version, which preserves the protocol  
of the original but (IMO) labels the parts better:

def makeStitch(var otherLast :vow[Stitch]) :Stitch {
     def stitch

     var state {
         to apply(func, item) {
             def oldLast := otherLast
             otherLast := makeStitch(stitch)
             oldLast.store(item, otherLast)
         }

         to store(storedItem, next) {
             state := def middleState {
                 to apply(func, item) {
                     func <- (storedItem)
                     next.apply(func, item)
                 }
             }
         }
     }

     bind stitch implements StitchStamp {
         match msg { E.callWithPair(state, msg) }
     }
     return stitch
}

While this is an improvement, I still prefer the version I posted  
with the separate makeCollector.

>> Given the patterns of usage so far, does that makeStitchPair do  
>> anything that the following (which is built out of pieces I  
>> understand) doesn't?
>
> No, I believe it is equivalent. Further, since (unlike Joule) we're  
> building on a system that already primitively supports promises,  
> your code maybe a better starting point than mine for adding  
> Joule's choose operator.

Could you/Dean/whoever tell me about the choose operator?

-- 
Kevin Reid                            <http://homepage.mac.com/kpreid/>




More information about the e-lang mailing list