A quick analogy:

A "co-expression" is like flash-freezing an expression and sticking it in
the freezer for later use.

So, when you say

function(1 to 10), that evaluates the generator "1 to 10" right there
place when the function is called and the function is called, possibly
multiple times, with a single number as a parameter.


But, if you say
function(create(1 to 10))

or almost equivalently*

function{1 to 10}

Then the whole generator "1 to 10" is wrapped in dry ice, packed up in a
box and sent to the function.

Then you can get values from the generator, 1 at a time, using the @
operator, which you can think of as thawing the expression enough to get
out one value, and sticking it back in the freezer.

So:

function(create(1 to 10))
...
procedure function(coexpr)
        while n := @coexpr do {
                write(n)
        }
end

writes:
1
2
3
4
5
6
7
8
9
10

Hope this helps,

Louis

* the {} syntax sticks all the parameters into an array, otherwise it is
equivalent.


On Wed, 29 Oct 2003, Hiroshi Shinohara wrote:

>
> Steve >While the above works, that's actually quite a bit of
> Steve >work that using a co-expression as Louis suggested
> Steve >avoids.  In fact, your problem is a good fit for
> Steve >a PDCO, (which can be thought of as fancy syntax
> Steve >to avoid writing 'create'...):
>
> Chap 9. Co-Expression is one of chapters I cannot understand
> in "The Icon Programming Languge".
>
> I'll try to understand Co-Expression again.
>
> Thanks,
> Hiroshi Shinohara
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: SF.net Giveback Program.
> Does SourceForge.net help you be more productive?  Does it
> help you create better code?   SHARE THE LOVE, and help us help
> YOU!  Click Here: http://sourceforge.net/donate/
> _______________________________________________
> Unicon-group mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/unicon-group
>


-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?   SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/
_______________________________________________
Unicon-group mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/unicon-group

Reply via email to