Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

[We] use bad software and bad machines for the wrong things. -- R. W. Hamming


devel / comp.lang.tcl / Re: somehow the "return -level" has a problem

SubjectAuthor
* somehow the "return -level" has a problemaotto1968
`* Re: somehow the "return -level" has a problemAndreas Leitgeb
 `* Re: somehow the "return -level" has a problemAndreas Leitgeb
  `- Re: somehow the "return -level" has a problemSteve Bennett

1
somehow the "return -level" has a problem

<u0od51$nkqb$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: aotto1968@t-online.de (aotto1968)
Newsgroups: comp.lang.tcl
Subject: somehow the "return -level" has a problem
Date: Fri, 7 Apr 2023 08:27:44 +0200
Organization: A noiseless patient Spider
Lines: 62
Message-ID: <u0od51$nkqb$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 7 Apr 2023 06:27:45 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="6ea0ad81abc09251a43b35a72ba8c8aa";
logging-data="774987"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18xoZHpMg7bB8MCWPHw8NX7Vv7Dq5d7+Zw="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.9.0
Cancel-Lock: sha1:BAbrCmaeAt+2pvfdycusiHn8X/4=
Content-Language: en-US
 by: aotto1968 - Fri, 7 Apr 2023 06:27 UTC

hi,

this is probably already known BUT the "-level" option in "return" does NOT cover the nested loop

the read the following code:

../level-bug.tcl
--------------------------------------
#!/bin/env tclsh

set lvl [lindex $argv 0]

while true {
while true {
puts [info frame $lvl]
return -level $lvl -code break
puts 0
break
}
puts 1
break
} puts 2
------------------------------------

> ./level-bug.tcl 0
type source line 7 file /home/dev1usr/test/level-bug.tcl cmd {info frame $lvl} level 0
1 2

> ./level-bug.tcl 1
type source line 5 file /home/dev1usr/test/level-bug.tcl cmd {while true {
while true {
puts [info frame $lvl]
return -level $lvl -code break
puts 0
break
}
puts 1
break
}} level 0
invoked "break" outside of a loop
while executing
"while true {
while true {
puts [info frame $lvl]
return -level $lvl -code break
puts 0
break
}
puts 1
..."
(file "./level-bug.tcl" line 5)

obvious the while count NOT as level/frame

mfg

Re: somehow the "return -level" has a problem

<slrnu5mhd6.1v30n.avl@logic.at>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: avl@logic.at (Andreas Leitgeb)
Newsgroups: comp.lang.tcl
Subject: Re: somehow the "return -level" has a problem
Date: Wed, 10 May 2023 07:20:06 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <slrnu5mhd6.1v30n.avl@logic.at>
References: <u0od51$nkqb$1@dont-email.me>
Reply-To: avl@logic.at
Injection-Date: Wed, 10 May 2023 07:20:06 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="3f832bc1a85c5a4cc846de198d1c9ecd";
logging-data="658513"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/iEsKqFlnc8v6B8hBKbnH/"
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:V90gE8EI+bk+SY4L2a2WeQGS6K0=
 by: Andreas Leitgeb - Wed, 10 May 2023 07:20 UTC

aotto1968 <aotto1968@t-online.de> wrote:
> this is probably already known BUT the "-level" option in "return" does NOT cover the nested loop

You're misunderstanding the "-level" of return (even with -code)

The -level was made, so procedures could act like "break", "continue"
or "return" themselves:
proc mybreak {} { return -level 1 -code break } ;# behaves just like "break"

proc myreturnlevel1codebreak {} { return -level 2 -code break }
# ^-- the procedure behaves like "return -level 1 -code break"
proc mybreak2 {} { myreturnlevel1codebreak } ;# again behaves just like "break"

There is no direct way to exit two loops at once, but of course you can do:

proc break3code {} { return 42 } ;# define an arbitrary numeric code once
proc break3 {} { return -code [break3code] } ;# -level 1 is default for return

try {
while true {
while true {
while true {
break3
}
}
}
} on [break3code] {} {};# we broke out of all loops, now continue happily.

Yes, it's a bit awkward, but breaking out of multiple loops isn't all that common.

Re: somehow the "return -level" has a problem

<slrnu5plg0.4ls.avl@logic.at>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: avl@logic.at (Andreas Leitgeb)
Newsgroups: comp.lang.tcl
Subject: Re: somehow the "return -level" has a problem
Date: Thu, 11 May 2023 11:48:16 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <slrnu5plg0.4ls.avl@logic.at>
References: <u0od51$nkqb$1@dont-email.me> <slrnu5mhd6.1v30n.avl@logic.at>
Reply-To: avl@logic.at
Injection-Date: Thu, 11 May 2023 11:48:16 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="0bea5536d4a022d16ba37d5f23cfd71f";
logging-data="1152286"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19C5vO5TTOtuhLdam1pKPw7"
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:xd49UwqnePOXdIO/ma7wwE4kEf0=
 by: Andreas Leitgeb - Thu, 11 May 2023 11:48 UTC

Andreas Leitgeb <avl@logic.at> wrote:
> aotto1968 <aotto1968@t-online.de> wrote:
>> this is probably already known BUT the "-level" option in "return" does NOT cover the nested loop
> You're misunderstanding the "-level" of return (even with -code)
>
> proc break3code {} { return 42 } ;# define an arbitrary numeric code once
> proc break3 {} { return -code [break3code] } ;# -level 1 is default for return
> try {
> while true {
> while true {
> while true {
> break3
> }
> }
> }
> } on [break3code] {} {};# we broke out of all loops, now continue happily.
>
> Yes, it's a bit awkward, but breaking out of multiple loops isn't all that common.
That example was just to show how it *could* be done with exceptional
exits...

A more common approach instead would rather look like this:

set emergencybreak 0
while true {
while true {
while true {
set emergencybreak 1; break
}
if {$emergencybreak} { break }
}
if {$emergencybreak} { break }
}

Re: somehow the "return -level" has a problem

<777184b2-0499-4246-8f61-aa644983e463n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:620a:4054:b0:74e:18e:8eda with SMTP id i20-20020a05620a405400b0074e018e8edamr7682529qko.4.1683937814823;
Fri, 12 May 2023 17:30:14 -0700 (PDT)
X-Received: by 2002:a05:620a:2a07:b0:759:2fe:9931 with SMTP id
o7-20020a05620a2a0700b0075902fe9931mr2965077qkp.15.1683937814591; Fri, 12 May
2023 17:30:14 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!1.us.feeder.erje.net!feeder.erje.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Fri, 12 May 2023 17:30:14 -0700 (PDT)
In-Reply-To: <slrnu5plg0.4ls.avl@logic.at>
Injection-Info: google-groups.googlegroups.com; posting-host=159.196.12.36; posting-account=YfjdmwoAAABFXkZI30zDyVM7AnEO5WTj
NNTP-Posting-Host: 159.196.12.36
References: <u0od51$nkqb$1@dont-email.me> <slrnu5mhd6.1v30n.avl@logic.at> <slrnu5plg0.4ls.avl@logic.at>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <777184b2-0499-4246-8f61-aa644983e463n@googlegroups.com>
Subject: Re: somehow the "return -level" has a problem
From: steveb@workware.net.au (Steve Bennett)
Injection-Date: Sat, 13 May 2023 00:30:14 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2554
 by: Steve Bennett - Sat, 13 May 2023 00:30 UTC

On Thursday, May 11, 2023 at 9:50:12 PM UTC+10, Andreas Leitgeb wrote:
> Andreas Leitgeb <a...@logic.at> wrote:
> > aotto1968 <aott...@t-online.de> wrote:
> >> this is probably already known BUT the "-level" option in "return" does NOT cover the nested loop
> > You're misunderstanding the "-level" of return (even with -code)
> >
> > proc break3code {} { return 42 } ;# define an arbitrary numeric code once
> > proc break3 {} { return -code [break3code] } ;# -level 1 is default for return
> > try {
> > while true {
> > while true {
> > while true {
> > break3
> > }
> > }
> > }
> > } on [break3code] {} {};# we broke out of all loops, now continue happily.
> >
> > Yes, it's a bit awkward, but breaking out of multiple loops isn't all that common.
> That example was just to show how it *could* be done with exceptional
> exits...
>
> A more common approach instead would rather look like this:
>
> set emergencybreak 0
> while true {
> while true {
> while true {
> set emergencybreak 1; break
> }
> if {$emergencybreak} { break }
> }
> if {$emergencybreak} { break }
> }

This prompted me to propose support for multi-level break and continue in Jim Tcl.
See:

https://github.com/msteveb/jimtcl/pull/261


devel / comp.lang.tcl / Re: somehow the "return -level" has a problem

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor