List Info

Thread: Qestion about generators




Qestion about generators
user name
2006-07-02 07:22:12

On 2006-07-02, Jeremy Tregunna <jtregunnablurgle.ca> wrote:
&gt; Your code is in need of some work (or at least, how I would have
> written it). Here's my version (works as expected with latest Io):
>
> // clip here ---
> generator := Object clone do(
> newSlot(&quot;value&quot;)
>; newSlot(&quot;input&quot;)
>; newSlot(&quot;coro&quot;)
> newSlot(&quot;waitingCoro")
>
&gt; run := method(
&gt; coro = coroDo(
&gt; pause
>; 0 to(1000) foreach(i,
> setValue(i + input)
&gt; waitingCoro resume
&gt; )
> )
> )
>
&gt; next := method(v,
> setInput(v)
> setWaitingCoro(Coroutine currentCoro)
> coro resume
&gt; value
>; )
> )
>
&gt; generator run
> generator next(10) println
&gt; generator next(100) println
&gt; generator next(1000) println
&gt;
> // clip here ---

Thanks, very nice!

&gt; If you have any problems, or questions; let me know.

Yes, I have both. Let's start with the most weird of them:
The code works as expected with the io binary, but gets blocked
before anything could happen if I'm using ioServer.

I compiled these binaries from yesterday's code, on FreeBSD 6.0.

Regards,
Csaba

__._,_.___
.

__,_._,___
Qestion about generators
user name
2006-07-02 08:29:57


On 2-Jul-06, at 3:22 AM, Csaba Henk wrote:

> On 2006-07-02, Jeremy Tregunna <jtregunnablurgle.ca> wrote:
&gt;> If you have any problems, or questions; let me know.
>;
> Yes, I have both. Let's start with the most weird of them:
>; The code works as expected with the io binary, but gets blocked
&gt; before anything could happen if I'm using ioServer.

Interesting; seems to be a problem with Ranges. If you change line 12
to read:

for(i, 0, 1000,

instead, it works as expected with ioServer / ioDesktop.

Rewriting ranges is on my list of things to do.

>; Csaba

--
Jeremy Tregunna
jtregunnablurgle.ca

";One serious obstacle to the adoption of good programming languages
is the notion that everything has to be sacrificed for speed. In
computer languages as in life, speed kills.&quot; -- Mike Vanier

__._,_.___
.

__,_._,___
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )