Andrew Clarke wrote:
> Interesting - I'll have a play with that in the context. I'm not fussed about 
> how scrappy a Lambda function would have to be, but the place where the 
> anonymous code block goes - ie on the create or { } - should avoid noise just 
> to get it started.

I understand why you'd want to avoid 'noise' if you don't have anything
you want done as initialization.  C-expressions were created [sorry] to
model co-routines, with @ as 'synchronization' points between them,
so doing work before reaching a synchronization point is natural in
that model, but less so if all you want is to use them as just
'in-line' functions.

Often you can reduce the noise, but it'll always be there.  For
example, the previous code I sent could also have been written as:

worker(10,20, lambda{X:=[0];|(X := (X[1]*X[1])@&source})

which should (untested!) produce identical results.  I didn't
show this initially because the boundary between 'initialization'
and 'first' user activation isn't as clear.

Part of the issue is that @ is more than a 'return' - it is
a synchronization point.  Aside from being viewed as a
'suspend', it can also be viewed as a point where the
expression can be 'called' [i.e. the caller as no way of
determining if it is 'calling' a CE at the start or partway
through the code, so passing arguments using two different
mechanisms is harder than it looks.  This doesn't arise in
other languages because their lambda functions don't have
the concept of 'suspending' in the same way co-expressions
do, so they can *only* pass information into the expression at
the start.  [You might start looking at what it would take
to get Perl, C@, etc. to provide what Unicon gives you to
see why it's so difficult to have both types of invocation.]

I personally like the extra expressive flexibility that Unicon has
here, even it it does mean I have to think slightly differently
than I would when using some other language.

Your idea of using $define is interesting.  It could be used, I think,
to hide the initialization, by 'looking' as though you're
declaring the parameters.  Something like (I probably have the syntax
wrong as I don't use $define normally):

$define def(X) X := @source

then you'd have:

worker(10,10,lambda {def(X); |(X := (X[1]*X[1])@&source)})

You could probably use a similar define to hide the code that
the synchronization point.

The risk is, though, that people might think it's doing more than
it is.

-- 
Steve Wampler -- [email protected]
The gods that smiled on your birth are now laughing out loud.

------------------------------------------------------------------------------
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

Reply via email to