Andrew Clarke wrote:
>> How about the following:
>>
>> procedure makeLamda(ce)
>> return (@ce, ce)
>> end
>>
>> This will perform the initial activation of the coexpression and then
>> return the coexpression. You have to write your co-expression with that
>> in mind.
>>
> Meaning it would have to lead with a suspend?
Sorta, kinda. Not really a suspend, but the code needs to understand
that it will be activated once as an 'initialization phase' with
no values passed in and then run until it reaches a point where it is
prepared to receive values. The lambda() procedure:
procedure lambda(A)
return (@A[1], A[1])
end
simply 'initializes' the co-expression when it is created, so the first
activation the *user sees* can take values. So, as long as you take
this initialization phase into account you get the same behavior as
if the CE took parameters right at the start. This initialization phase
can be looked on a bonus - you get to set things up before receiving
parameters. If you don't have anything to set up, then starting your
co-expression with (say):
X := @&source
will assign the 'first call' (as seen outside the lambda procedure
itself) parameters to X just as other languages can assign values to
parameters as part of a call.
Also, note that Unicon already supports CE(a,b,c) style activation (as
the example program I gave shows), which is equivalent to [a,b,c...@ce.
Again, you have to write your co-expression knowing that it's getting
a list of values, but that's not too hard.
For example, the Perl example you gave is nearly the same as:
worker(10, 20,
lambda { X := @&source; |(X := (X[1]*X[1]) @ &source) }
)
{Spread out to avoid line wrap on my mailer.}
So, if worker is:
procedure worker(a,b,ce)
every i := a to b do
write(i,"*",i," = ",ce(i,i))
end
you get what you'd expect.
Not that I've tried this, mind you!
--
Steve Wampler {[email protected]}
The gods that smiled upon your birth are laughing now. -- fortune cookie
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Unicon-group mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/unicon-group