Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Always draw your curves, then plot your reading.


devel / comp.lang.tcl / Re: Coroutine problem

SubjectAuthor
* Coroutine problemSimon Geard
`* Re: Coroutine problemChristian Gollwitzer
 +- Re: Coroutine problemChristian Gollwitzer
 `- Re: Coroutine problemSimon Geard

1
Coroutine problem

<tabpmd$119if$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19652&group=comp.lang.tcl#19652

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: simon@whiteowl.co.uk (Simon Geard)
Newsgroups: comp.lang.tcl
Subject: Coroutine problem
Date: Sat, 9 Jul 2022 12:44:12 +0100
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <tabpmd$119if$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 9 Jul 2022 11:44:13 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="e0f6a27e758090ff4463f0c916189e79";
logging-data="1091151"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/5XX6WW2+4A2segf13j/fK"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.11.0
Cancel-Lock: sha1:gJkFQA4LS2CyiQCL4OUmVLHu8GY=
Content-Language: en-GB
 by: Simon Geard - Sat, 9 Jul 2022 11:44 UTC

I'm trying to use a coroutine to iterate over a list so that I get the
index as well:

proc list_sequencer {o} {
yield
set i 0
while {$i < [llength $o]} {
yield [list $i [lindex $o $i]]
incr i
}
return -code break
}

set tl {s i m p l e}
coroutine next_element list_sequencer $tl
while {1} {
lassign [next_element] idx e
puts "$idx -> $e"
} exit 0

When I run it I get
0 -> s
1 -> i
2 -> m
3 -> p
4 -> l
5 -> e
invoked "break" outside of a loop
while executing

but don't understand why. Any help greatly appreciated!

Simon

Re: Coroutine problem

<tabv7g$11rse$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19653&group=comp.lang.tcl#19653

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: auriocus@gmx.de (Christian Gollwitzer)
Newsgroups: comp.lang.tcl
Subject: Re: Coroutine problem
Date: Sat, 9 Jul 2022 15:18:39 +0200
Organization: A noiseless patient Spider
Lines: 55
Message-ID: <tabv7g$11rse$1@dont-email.me>
References: <tabpmd$119if$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 9 Jul 2022 13:18:40 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="8f9c4b3aa1d14f8fb4d93d70080cd5e2";
logging-data="1109902"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX193gS90jMhZnQHGGabPi3kGAhUb4x2voPE="
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:91.0)
Gecko/20100101 Thunderbird/91.11.0
Cancel-Lock: sha1:SRMP+GD7VjSXR0IduJd3dA4rVFk=
In-Reply-To: <tabpmd$119if$1@dont-email.me>
 by: Christian Gollwitzer - Sat, 9 Jul 2022 13:18 UTC

Am 09.07.22 um 13:44 schrieb Simon Geard:
> I'm trying to use a coroutine to iterate over a list so that I get the
> index as well:
>
> proc list_sequencer {o} {
>     yield
>     set i 0
>     while {$i < [llength $o]} {
>         yield [list $i [lindex $o $i]]
>         incr i
>     }
>     return -code break
> }
>
> set tl {s i m p l e}
> coroutine next_element list_sequencer $tl
> while {1} {
>     lassign [next_element] idx e
>     puts "$idx -> $e"
> }
> exit 0
>
>
> When I run it I get
> 0 -> s
> 1 -> i
> 2 -> m
> 3 -> p
> 4 -> l
> 5 -> e
> invoked "break" outside of a loop
>     while executing
>
> but don't understand why. Any help greatly appreciated!

I think you cannot yield an error code, that was missed out in the
original definition of yield. The manpage
https://www.tcl.tk/man/tcl/TclCmd/coroutine.html recommends to use
"yieldto return", and in fact this works:

proc list_sequencer {o} {
yield
set i 0
while {$i < [llength $o]} {
yield [list $i [lindex $o $i]]
incr i
}
yieldto return -code break -level 0
}

However, there is a strange side effect that if I run this in tkcon, the
breaks terminates the tkcon. Maybe some coro guru can comment on it.

Christian

Re: Coroutine problem

<tabvjg$11sqt$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19654&group=comp.lang.tcl#19654

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!paganini.bofh.team!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: auriocus@gmx.de (Christian Gollwitzer)
Newsgroups: comp.lang.tcl
Subject: Re: Coroutine problem
Date: Sat, 9 Jul 2022 15:25:04 +0200
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <tabvjg$11sqt$1@dont-email.me>
References: <tabpmd$119if$1@dont-email.me> <tabv7g$11rse$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 9 Jul 2022 13:25:04 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="8dccb482774e5c8459c3a938ed34752a";
logging-data="1110877"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/VQBfPGLqBaFhXIgbbNiWZ4lr6ofI0sys="
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:91.0)
Gecko/20100101 Thunderbird/91.11.0
Cancel-Lock: sha1:LBfjJsK7zybtaOO5Vrx52PE0bAM=
In-Reply-To: <tabv7g$11rse$1@dont-email.me>
 by: Christian Gollwitzer - Sat, 9 Jul 2022 13:25 UTC

Am 09.07.22 um 15:18 schrieb Christian Gollwitzer:

> proc list_sequencer {o} {
>     yield
>     set i 0
>     while {$i < [llength $o]} {
>         yield [list $i [lindex $o $i]]
>         incr i
>     }
>     yieldto return -code break -level 0
> }
>
> However, there is a strange side effect that if I run this in tkcon, the
> breaks terminates the tkcon. Maybe some coro guru can comment on it.
>

Found the error: The "exit 0" in the original code terminates tkcon,
therefore everything works as expected using this code! There is another
(potential) problem only: After the "yieldto return" the coroutine still
exists and must be executed one more time in order to be destroyed. THis
might introduce memory leaks, depending on the usage.

Christan

Re: Coroutine problem

<taccu5$13blr$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19656&group=comp.lang.tcl#19656

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: simon@whiteowl.co.uk (Simon Geard)
Newsgroups: comp.lang.tcl
Subject: Re: Coroutine problem
Date: Sat, 9 Jul 2022 18:12:37 +0100
Organization: A noiseless patient Spider
Lines: 60
Message-ID: <taccu5$13blr$1@dont-email.me>
References: <tabpmd$119if$1@dont-email.me> <tabv7g$11rse$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 9 Jul 2022 17:12:37 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="e0f6a27e758090ff4463f0c916189e79";
logging-data="1158843"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/37KzaAkSuVH79FWHeP4ma"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.11.0
Cancel-Lock: sha1:GUMcJzzB6hAWwRUNb+q6+kuHcEs=
Content-Language: en-GB
In-Reply-To: <tabv7g$11rse$1@dont-email.me>
 by: Simon Geard - Sat, 9 Jul 2022 17:12 UTC

On 09/07/2022 14:18, Christian Gollwitzer wrote:
> Am 09.07.22 um 13:44 schrieb Simon Geard:
>> I'm trying to use a coroutine to iterate over a list so that I get the
>> index as well:
>>
>> proc list_sequencer {o} {
>>      yield
>>      set i 0
>>      while {$i < [llength $o]} {
>>          yield [list $i [lindex $o $i]]
>>          incr i
>>      }
>>      return -code break
>> }
>>
>> set tl {s i m p l e}
>> coroutine next_element list_sequencer $tl
>> while {1} {
>>      lassign [next_element] idx e
>>      puts "$idx -> $e"
>> }
>> exit 0
>>
>>
>> When I run it I get
>> 0 -> s
>> 1 -> i
>> 2 -> m
>> 3 -> p
>> 4 -> l
>> 5 -> e
>> invoked "break" outside of a loop
>>      while executing
>>
>> but don't understand why. Any help greatly appreciated!
>
> I think you cannot yield an error code, that was missed out in the
> original definition of yield. The manpage
> https://www.tcl.tk/man/tcl/TclCmd/coroutine.html recommends to use
> "yieldto return", and in fact this works:
>
> proc list_sequencer {o} {
>     yield
>     set i 0
>     while {$i < [llength $o]} {
>         yield [list $i [lindex $o $i]]
>         incr i
>     }
>     yieldto return -code break -level 0
> }
>
> However, there is a strange side effect that if I run this in tkcon, the
> breaks terminates the tkcon. Maybe some coro guru can comment on it.
>
>
>     Christian

Thank you. yieldto worked perfectly.

Simon


devel / comp.lang.tcl / Re: Coroutine problem

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor