Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

A pain in the ass of major dimensions. -- C. A. Desoer, on the solution of non-linear circuits


devel / comp.lang.tcl / How do I make a proc return the output of a sub proc?

SubjectAuthor
* How do I make a proc return the output of a sub proc?Luc
+* How do I make a proc return the output of a sub proc?Arjen Markus
|+- How do I make a proc return the output of a sub proc?heinrichmartin
|`* How do I make a proc return the output of a sub proc?Luc
| +* How do I make a proc return the output of a sub proc?Luc
| |`* How do I make a proc return the output of a sub proc?Luc
| | `- How do I make a proc return the output of a sub proc?Harald Oehlmann
| `* How do I make a proc return the output of a sub proc?Ralf Fassel
|  `* How do I make a proc return the output of a sub proc?Rich
|   `* How do I make a proc return the output of a sub proc?Luc
|    +* How do I make a proc return the output of a sub proc?Gerald Lester
|    |+* How do I make a proc return the output of a sub proc?Robert Heller
|    ||`- How do I make a proc return the output of a sub proc?Gerald Lester
|    |`* How do I make a proc return the output of a sub proc?Luc
|    | +* How do I make a proc return the output of a sub proc?ted@loft.tnolan.com (Ted Nolan
|    | |`* How do I make a proc return the output of a sub proc?Luc
|    | | +- How do I make a proc return the output of a sub proc?saitology9
|    | | `- How do I make a proc return the output of a sub proc?Rich
|    | +* How do I make a proc return the output of a sub proc?Rich
|    | |`* How do I make a proc return the output of a sub proc?Luc
|    | | `- How do I make a proc return the output of a sub proc?Rich
|    | `- How do I make a proc return the output of a sub proc?Gerald Lester
|    +* How do I make a proc return the output of a sub proc?Robert Heller
|    |`* How do I make a proc return the output of a sub proc?Luc
|    | +- How do I make a proc return the output of a sub proc?Rich
|    | `* How do I make a proc return the output of a sub proc?Robert Heller
|    |  `* How do I make a proc return the output of a sub proc?Luc
|    |   `- How do I make a proc return the output of a sub proc?Robert Heller
|    `* How do I make a proc return the output of a sub proc?Rich
|     `* How do I make a proc return the output of a sub proc?Luc
|      +- How do I make a proc return the output of a sub proc?Ralf Fassel
|      +- How do I make a proc return the output of a sub proc?Robert Heller
|      `- How do I make a proc return the output of a sub proc?Rich
+- How do I make a proc return the output of a sub proc?Rich
+* How do I make a proc return the output of a sub proc?Ralf Fassel
|`- How do I make a proc return the output of a sub proc?saitology9
`- How do I make a proc return the output of a sub proc?saitology9

Pages:12
How do I make a proc return the output of a sub proc?

<20221104033658.73503ea1@lud1.home>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!Ak23d9c4bhSNPY8CFs7nEQ.user.46.165.242.75.POSTED!not-for-mail
From: no...@no.no (Luc)
Newsgroups: comp.lang.tcl
Subject: How do I make a proc return the output of a sub proc?
Date: Fri, 4 Nov 2022 03:36:58 -0300
Organization: Aioe.org NNTP Server
Message-ID: <20221104033658.73503ea1@lud1.home>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="63973"; posting-host="Ak23d9c4bhSNPY8CFs7nEQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Notice: Filtered by postfilter v. 0.9.2
X-Newsreader: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu)
 by: Luc - Fri, 4 Nov 2022 06:36 UTC

Gentlemen, please:

--------------------
#!/usr/bin/env tclsh

proc outside {} {
proc inside {} {
return "deep thoughts"
}
inside
return "shallow thoughts"
}

puts [outside]
--------------------

How do I get the outside proc to return "deep thoughts"?

--
Luc
>>

Re: How do I make a proc return the output of a sub proc?

<b0cf1159-1065-4eed-9d24-064c8cdc7983n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:620a:cc5:b0:6fa:29f2:53df with SMTP id b5-20020a05620a0cc500b006fa29f253dfmr19816683qkj.194.1667547198547;
Fri, 04 Nov 2022 00:33:18 -0700 (PDT)
X-Received: by 2002:a37:c4e:0:b0:6fa:c1c:6fc0 with SMTP id 75-20020a370c4e000000b006fa0c1c6fc0mr25335407qkm.501.1667547198383;
Fri, 04 Nov 2022 00:33:18 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.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, 4 Nov 2022 00:33:18 -0700 (PDT)
In-Reply-To: <20221104033658.73503ea1@lud1.home>
Injection-Info: google-groups.googlegroups.com; posting-host=62.194.189.128; posting-account=A91wAAoAAADgBUxBX6QqsrSD26GLhVp8
NNTP-Posting-Host: 62.194.189.128
References: <20221104033658.73503ea1@lud1.home>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <b0cf1159-1065-4eed-9d24-064c8cdc7983n@googlegroups.com>
Subject: Re: How do I make a proc return the output of a sub proc?
From: arjen.ma...@gmail.com (Arjen Markus)
Injection-Date: Fri, 04 Nov 2022 07:33:18 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1937
 by: Arjen Markus - Fri, 4 Nov 2022 07:33 UTC

On Friday, November 4, 2022 at 7:37:09 AM UTC+1, Luc wrote:
> Gentlemen, please:
>
> --------------------
> #!/usr/bin/env tclsh
>
> proc outside {} {
>
> proc inside {} {
> return "deep thoughts"
> }
> inside
> return "shallow thoughts"
> }
>
> puts [outside]
> --------------------
>
> How do I get the outside proc to return "deep thoughts"?
>
>
> --
> Luc
> >>

You can do:

proc outside {} {
proc inside {} {
return "deep thoughts"
}
return [inside]
# return "shallow thoughts" --- wil not be reached
}
puts [outside]

But you should note that by putting the definition of "inside" inside the body of "outside", it is created each time "outside" is called.

Perhaps you should explain to us what you want to do?

Regards,

Arjen

Re: How do I make a proc return the output of a sub proc?

<2a426195-6c15-49f0-acaa-987380345645n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:ad4:5fcd:0:b0:4bb:f8f2:1ebf with SMTP id jq13-20020ad45fcd000000b004bbf8f21ebfmr23089750qvb.66.1667549130602;
Fri, 04 Nov 2022 01:05:30 -0700 (PDT)
X-Received: by 2002:ac8:64a:0:b0:3a5:3592:8d0c with SMTP id
e10-20020ac8064a000000b003a535928d0cmr16075818qth.138.1667549130427; Fri, 04
Nov 2022 01:05:30 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.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, 4 Nov 2022 01:05:30 -0700 (PDT)
In-Reply-To: <b0cf1159-1065-4eed-9d24-064c8cdc7983n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=84.115.226.75; posting-account=Od2xOAoAAACEyRX3Iu5rYt4oevuoeYUG
NNTP-Posting-Host: 84.115.226.75
References: <20221104033658.73503ea1@lud1.home> <b0cf1159-1065-4eed-9d24-064c8cdc7983n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <2a426195-6c15-49f0-acaa-987380345645n@googlegroups.com>
Subject: Re: How do I make a proc return the output of a sub proc?
From: martin.h...@frequentis.com (heinrichmartin)
Injection-Date: Fri, 04 Nov 2022 08:05:30 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2434
 by: heinrichmartin - Fri, 4 Nov 2022 08:05 UTC

On Friday, November 4, 2022 at 8:33:20 AM UTC+1, Arjen wrote:
> On Friday, November 4, 2022 at 7:37:09 AM UTC+1, Luc wrote:
> > Gentlemen, please:
> >
> > --------------------
> > #!/usr/bin/env tclsh
> >
> > proc outside {} {
> >
> > proc inside {} {
> > return "deep thoughts"
> > }
> > inside
> > return "shallow thoughts"
> > }
> >
> > puts [outside]
> > --------------------
> >
> > How do I get the outside proc to return "deep thoughts"?

Not returning "shallow thoughts" would implicitly return the return value of "inside".
A bit more code is needed, if inside should be hidden from return codes/levels. Pointing to the docs: catch or try or tailcall

Btw, I recall someone or some doc mention that explicit return is preferable over implicit return values.
I never fully understood that statement; maybe it is just defensive coding wrt maintainability.

> Perhaps you should explain to us what you want to do?

Luc, (if you were defining the proc inside the proc intentionally) are you looking for: apply or coroutine or namespace code?

Btw, looking at the doc of "namespace code", I think that "eval $script [list x y]" should be replaced with "{*}$script x y" in modern Tcl.

Re: How do I make a proc return the output of a sub proc?

<20221104050646.13fd3761@lud1.home>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!Ak23d9c4bhSNPY8CFs7nEQ.user.46.165.242.75.POSTED!not-for-mail
From: no...@no.no (Luc)
Newsgroups: comp.lang.tcl
Subject: Re: How do I make a proc return the output of a sub proc?
Date: Fri, 4 Nov 2022 05:06:46 -0300
Organization: Aioe.org NNTP Server
Message-ID: <20221104050646.13fd3761@lud1.home>
References: <20221104033658.73503ea1@lud1.home>
<b0cf1159-1065-4eed-9d24-064c8cdc7983n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="52677"; posting-host="Ak23d9c4bhSNPY8CFs7nEQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Notice: Filtered by postfilter v. 0.9.2
X-Newsreader: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu)
 by: Luc - Fri, 4 Nov 2022 08:06 UTC

**************************
On Fri, 4 Nov 2022 00:33:18 -0700 (PDT), Arjen Markus wrote:

> On Friday, November 4, 2022 at 7:37:09 AM UTC+1, Luc wrote:
> > Gentlemen, please:
> >
> > --------------------
> > #!/usr/bin/env tclsh
> >
> > proc outside {} {
> >
> > proc inside {} {
> > return "deep thoughts"
> > }
> > inside
> > return "shallow thoughts"
> > }
> >
> > puts [outside]
> > --------------------
> >
> > How do I get the outside proc to return "deep thoughts"?
> >
> >
> > --
> > Luc
> > >>
>
> You can do:
>
> proc outside {} {
>
> proc inside {} {
> return "deep thoughts"
> }
> return [inside]
> # return "shallow thoughts" --- wil not be reached
> }
> puts [outside]
>
> But you should note that by putting the definition of "inside" inside the
> body of "outside", it is created each time "outside" is called.
>
> Perhaps you should explain to us what you want to do?
>
> Regards,
>
> Arjen

OK, you're right. That doesn't work for me. I tried.

I have proc1.

Inside proc1, there is proc2.
Then proc2 creates widgets.
Multiple widgets may be manipulated until a decision is taken.
A button in a widget calls proc3.
Then proc 3 may or may not decide it's time for the entire
machine (proc1 *is* the entire machine) to return an output.
May or may not.

That's it.

--
Luc
>>

Re: How do I make a proc return the output of a sub proc?

<20221104052243.338b5a26@lud1.home>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!Ak23d9c4bhSNPY8CFs7nEQ.user.46.165.242.75.POSTED!not-for-mail
From: no...@no.no (Luc)
Newsgroups: comp.lang.tcl
Subject: Re: How do I make a proc return the output of a sub proc?
Date: Fri, 4 Nov 2022 05:22:43 -0300
Organization: Aioe.org NNTP Server
Message-ID: <20221104052243.338b5a26@lud1.home>
References: <20221104033658.73503ea1@lud1.home>
<b0cf1159-1065-4eed-9d24-064c8cdc7983n@googlegroups.com>
<20221104050646.13fd3761@lud1.home>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="52677"; posting-host="Ak23d9c4bhSNPY8CFs7nEQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Newsreader: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu)
X-Notice: Filtered by postfilter v. 0.9.2
 by: Luc - Fri, 4 Nov 2022 08:22 UTC

Hey, you know what works?

if {[condition ismet $_foobar]} {puts "Yes!"; exit}

But I'm afraid my tcler license will be revoked if I do that... :-)

Seriously, though. There must be a more "proper" way.

--
Luc
>>

Re: How do I make a proc return the output of a sub proc?

<20221104052625.4a9f6040@lud1.home>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!Ak23d9c4bhSNPY8CFs7nEQ.user.46.165.242.75.POSTED!not-for-mail
From: no...@no.no (Luc)
Newsgroups: comp.lang.tcl
Subject: Re: How do I make a proc return the output of a sub proc?
Date: Fri, 4 Nov 2022 05:26:25 -0300
Organization: Aioe.org NNTP Server
Message-ID: <20221104052625.4a9f6040@lud1.home>
References: <20221104033658.73503ea1@lud1.home>
<b0cf1159-1065-4eed-9d24-064c8cdc7983n@googlegroups.com>
<20221104050646.13fd3761@lud1.home>
<20221104052243.338b5a26@lud1.home>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="52677"; posting-host="Ak23d9c4bhSNPY8CFs7nEQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Newsreader: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu)
X-Notice: Filtered by postfilter v. 0.9.2
 by: Luc - Fri, 4 Nov 2022 08:26 UTC

No, that doesn't work either. I forgot I am prototyping the whole thing
as an independent creature, but it's supposed to be a proc once it's ready.
So it can't just exit. The entire application would die with it.

Never let anyone ask me to code for airports or railways.

--
Luc
>>

**************************
On Fri, 4 Nov 2022 05:22:43 -0300, Luc wrote:

> Hey, you know what works?
>
> if {[condition ismet $_foobar]} {puts "Yes!"; exit}
>
> But I'm afraid my tcler license will be revoked if I do that... :-)
>
> Seriously, though. There must be a more "proper" way.
>
************************

Re: How do I make a proc return the output of a sub proc?

<tk2jch$1n9kp$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: wortka...@yahoo.com (Harald Oehlmann)
Newsgroups: comp.lang.tcl
Subject: Re: How do I make a proc return the output of a sub proc?
Date: Fri, 4 Nov 2022 09:44:03 +0100
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <tk2jch$1n9kp$1@dont-email.me>
References: <20221104033658.73503ea1@lud1.home>
<b0cf1159-1065-4eed-9d24-064c8cdc7983n@googlegroups.com>
<20221104050646.13fd3761@lud1.home> <20221104052243.338b5a26@lud1.home>
<20221104052625.4a9f6040@lud1.home>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 4 Nov 2022 08:44:01 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="a0e56dfcf2af5852a773ba6f88ae4dc2";
logging-data="1812121"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1804N7AwKEkQsDKaJQjy8I2"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.4.1
Cancel-Lock: sha1:2pJEq7W06/pvNchkD//80Znbbuw=
Content-Language: en-GB
In-Reply-To: <20221104052625.4a9f6040@lud1.home>
 by: Harald Oehlmann - Fri, 4 Nov 2022 08:44 UTC

Am 04.11.2022 um 09:26 schrieb Luc:
> No, that doesn't work either. I forgot I am prototyping the whole thing
> as an independent creature, but it's supposed to be a proc once it's ready.
> So it can't just exit. The entire application would die with it.
>
> Never let anyone ask me to code for airports or railways.
>

Luc,

I am not sure, if this was mentioned.
A "one time use proc" may be defined with the "apply" command.

So, the following is a bit the same:

Create a proc, use it and remove it:

proc pn {a} {puts $a}
pn val1
rename pn ""

Now, with apply:

apply { {a} {
puts $a
}} val1

Take care,
Harald

Re: How do I make a proc return the output of a sub proc?

<ygasfiz6o4v.fsf@akutech.de>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: ralf...@gmx.de (Ralf Fassel)
Newsgroups: comp.lang.tcl
Subject: Re: How do I make a proc return the output of a sub proc?
Date: Fri, 04 Nov 2022 10:54:24 +0100
Lines: 11
Message-ID: <ygasfiz6o4v.fsf@akutech.de>
References: <20221104033658.73503ea1@lud1.home>
<b0cf1159-1065-4eed-9d24-064c8cdc7983n@googlegroups.com>
<20221104050646.13fd3761@lud1.home>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net gf9LiXlw06H3f0DyTonUvAW79YH10Ycs06aSLIyLgjwFAC2Ts=
Cancel-Lock: sha1:NgVPq4Xqgf/jiBCQ10Qnag+N9/M= sha1:AhnNhJ1IF9IwDEwXm+B/OaJyoSA=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
 by: Ralf Fassel - Fri, 4 Nov 2022 09:54 UTC

* Luc <no@no.no>
| I have proc1.
>
| Inside proc1, there is proc2.

Why is proc2 *inside* proc1?
Usually procs are defined at global scope and not inside other procs
(yes I know, there might be uses for that, but until explained by the OP
I'd rather assume some confusion about basic concepts here).

R'

Re: How do I make a proc return the output of a sub proc?

<tk34ge$1qd54$4@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: ric...@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: How do I make a proc return the output of a sub proc?
Date: Fri, 4 Nov 2022 13:36:14 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <tk34ge$1qd54$4@dont-email.me>
References: <20221104033658.73503ea1@lud1.home> <b0cf1159-1065-4eed-9d24-064c8cdc7983n@googlegroups.com> <20221104050646.13fd3761@lud1.home> <ygasfiz6o4v.fsf@akutech.de>
Injection-Date: Fri, 4 Nov 2022 13:36:14 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="4e8ea44998da3f7d079b142bcda36cfb";
logging-data="1914020"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/SWtGTcd2Num55OYDUnsnC"
User-Agent: tin/2.0.1-20111224 ("Achenvoir") (UNIX) (Linux/3.10.17 (x86_64))
Cancel-Lock: sha1:63i/VgTh7fJufsgeeMH+gFHQXP4=
 by: Rich - Fri, 4 Nov 2022 13:36 UTC

Ralf Fassel <ralfixx@gmx.de> wrote:
> * Luc <no@no.no>
> | I have proc1.
>>
> | Inside proc1, there is proc2.
>
> Why is proc2 *inside* proc1?

Indeed, an answer to this question is important.

> Usually procs are defined at global scope and not inside other procs
> (yes I know, there might be uses for that, but until explained by the OP
> I'd rather assume some confusion about basic concepts here).

Defining a proc during runtime within another proc is an advanced Tcl
technique that is in most cases not needed for instrumenting a GUI
(which is what the OP seems to be doing based on another post in this
thread).

Re: How do I make a proc return the output of a sub proc?

<tk34v4$1qd54$5@dont-email.me>

  copy mid

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

  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: ric...@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: How do I make a proc return the output of a sub proc?
Date: Fri, 4 Nov 2022 13:44:04 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 64
Message-ID: <tk34v4$1qd54$5@dont-email.me>
References: <20221104033658.73503ea1@lud1.home>
Injection-Date: Fri, 4 Nov 2022 13:44:04 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="4e8ea44998da3f7d079b142bcda36cfb";
logging-data="1914020"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Dnd5ced/eX3VNQgV99HmY"
User-Agent: tin/2.0.1-20111224 ("Achenvoir") (UNIX) (Linux/3.10.17 (x86_64))
Cancel-Lock: sha1:1ZttN2GpfiGUzBfukZ47iO/caNA=
 by: Rich - Fri, 4 Nov 2022 13:44 UTC

Luc <no@no.no> wrote:
> Gentlemen, please:
>
> --------------------
> #!/usr/bin/env tclsh
>
> proc outside {} {
>
> proc inside {} {
> return "deep thoughts"
> }
> inside
> return "shallow thoughts"
> }
>
> puts [outside]
> --------------------
>
> How do I get the outside proc to return "deep thoughts"?

Until we get an answer to Ralf's question, we can only offer replies
based upon your confusion about defining vs. calling.

However, guessing as to what you might mean (as in, you might mean "how
can I cause 'inside' to abort further execution of 'outside' and
instead cause 'outside' to return a value) here is one way to get
"outside" to return "deep thoughts":

#!/usr/bin/tclsh

# this below also fixes the confusion between 'defining' and
# 'calling' a proc

proc outside {} {
inside
return "shallow thoughts"
}

proc inside {} {
if {rand() < 0.5} {
return -code return "deep thoughts"
}
}

for {set i 0} {$i < 10} {incr i} {
puts "$i: [outside]"
}

Running this provides:

0: deep thoughts
1: shallow thoughts
2: shallow thoughts
3: shallow thoughts
4: deep thoughts
5: shallow thoughts
6: deep thoughts
7: shallow thoughts
8: shallow thoughts
9: shallow thoughts

Note that due to 'inside' using rand() to decide what to do, your
output will naturally be different (and each run will output a
different set of 'deep' vs. 'shallow' lines.

Re: How do I make a proc return the output of a sub proc?

<20221104113427.6cf60333@lud1.home>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!FDdzVMkD3aVN3D6MOWZmsQ.user.46.165.242.75.POSTED!not-for-mail
From: no...@no.no (Luc)
Newsgroups: comp.lang.tcl
Subject: Re: How do I make a proc return the output of a sub proc?
Date: Fri, 4 Nov 2022 11:34:27 -0300
Organization: Aioe.org NNTP Server
Message-ID: <20221104113427.6cf60333@lud1.home>
References: <20221104033658.73503ea1@lud1.home>
<b0cf1159-1065-4eed-9d24-064c8cdc7983n@googlegroups.com>
<20221104050646.13fd3761@lud1.home>
<ygasfiz6o4v.fsf@akutech.de>
<tk34ge$1qd54$4@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="38245"; posting-host="FDdzVMkD3aVN3D6MOWZmsQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Notice: Filtered by postfilter v. 0.9.2
X-Newsreader: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu)
 by: Luc - Fri, 4 Nov 2022 14:34 UTC

**************************
On Fri, 4 Nov 2022 13:36:14 -0000 (UTC), Rich wrote:

> Ralf Fassel <ralfixx@gmx.de> wrote:
> > Why is proc2 *inside* proc1?

> Indeed, an answer to this question is important.

************************

I believe the answer is pretty obvious.

It's a large proc. I need to organize everything in sub functions
inside the function.

I have been quite clear about what I need. Again:

I have proc1.

Inside proc1, there is proc2 and about 20 other procs.
Then proc2 creates widgets AND it calls many other procs in the process.
Multiple widgets may be manipulated until a decision is taken. Each one
of them also calls a number of procs. It's all a matter of organization.
A button in a widget calls proc3.
Then proc 3 also calls a bunch of other procs and meanwhile it may
or may not decide it's time for the big parent proc to return an output.

It's all a matter of organization.

It's 1,900 lines of code. And yes, I'm afraid it may be a little spaghetti
here and there. I will improve it later. But this is not the best time to post
more code. Please consider just the description above. The entire code will be
published eventually and I will be very open to criticism, but I can't publish
something that doesn't work.

I was almost sure someone would suggest uplevel, but nobody has and I have
tried it on my own, it doesn't seem to work.

The return -code return "deep thoughts" idea doesn't work either.
The "deep thoughts" example I posted previously is too simple to reflect
what I have here. I basically need a command that says
STOP EVERYTHING RIGHT NOW, RETURN THIS STRING AND DISAPPEAR

--
Luc
>>

Re: How do I make a proc return the output of a sub proc?

<tk3adu$14u3$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!W8/fhIku2mFEvQF8+99Hqw.user.46.165.242.75.POSTED!not-for-mail
From: Gerald.L...@KnG-Consulting.net (Gerald Lester)
Newsgroups: comp.lang.tcl
Subject: Re: How do I make a proc return the output of a sub proc?
Date: Fri, 4 Nov 2022 10:17:17 -0500
Organization: KnG Consulting, LLC
Message-ID: <tk3adu$14u3$1@gioia.aioe.org>
References: <20221104033658.73503ea1@lud1.home>
<b0cf1159-1065-4eed-9d24-064c8cdc7983n@googlegroups.com>
<20221104050646.13fd3761@lud1.home> <ygasfiz6o4v.fsf@akutech.de>
<tk34ge$1qd54$4@dont-email.me> <20221104113427.6cf60333@lud1.home>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="37827"; posting-host="W8/fhIku2mFEvQF8+99Hqw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.11.0
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: Gerald Lester - Fri, 4 Nov 2022 15:17 UTC

On 11/4/22 09:34, Luc wrote:
> **************************
> On Fri, 4 Nov 2022 13:36:14 -0000 (UTC), Rich wrote:
>
>> Ralf Fassel <ralfixx@gmx.de> wrote:
>>> Why is proc2 *inside* proc1?
>
>> Indeed, an answer to this question is important.
>
> ************************
>
> I believe the answer is pretty obvious.
>
> It's a large proc. I need to organize everything in sub functions
> inside the function.

Ah, you do realize that all procs are globally addressable -- there is
no such thing as a sub function in Tcl.

A Tcl proc, can have another proc declared inside of it -- but that just
causes it to be defined/redefined at runtime and it can be called by anyone.

Now a Tcl proc can *call* another function, but that does not make it
"inside" nor does it make it a aub function.

>...
> The return -code return "deep thoughts" idea doesn't work either.
> The "deep thoughts" example I posted previously is too simple to reflect
> what I have here. I basically need a command that says
> STOP EVERYTHING RIGHT NOW, RETURN THIS STRING AND DISAPPEAR

You need to combine [info level] with [return] -- please read both
man/help pages in detail and pay close attention to the level option on
the return.

--
+----------------------------------------------------------------------+
| Gerald W. Lester, President, KNG Consulting LLC |
| Email: Gerald.Lester@kng-consulting.net |
+----------------------------------------------------------------------+

Re: How do I make a proc return the output of a sub proc?

<OP-cnbHzc9wcrvj-nZ2dnZfqnPidnZ2d@giganews.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr1.iad1.usenetexpress.com!69.80.99.27.MISMATCH!Xl.tags.giganews.com!local-2.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Fri, 04 Nov 2022 15:45:05 +0000
MIME-Version: 1.0
From: hel...@deepsoft.com (Robert Heller)
Organization: Deepwoods Software
X-Newsreader: TkNews 3.0 (1.2.15)
Subject: Re: How do I make a proc return the output of a sub proc?
In-Reply-To: <20221104113427.6cf60333@lud1.home>
References: <20221104033658.73503ea1@lud1.home>??<b0cf1159-1065-4eed-9d24-064c8cdc7983n@googlegroups.com>??<20221104050646.13fd3761@lud1.home>??<ygasfiz6o4v.fsf@akutech.de>??<tk34ge$1qd54$4@dont-email.me> <20221104113427.6cf60333@lud1.home>
Newsgroups: comp.lang.tcl
Content-Type: text/plain; charset="us-ascii"
Originator: heller@sharky4.deepsoft.com
Message-ID: <OP-cnbHzc9wcrvj-nZ2dnZfqnPidnZ2d@giganews.com>
Date: Fri, 04 Nov 2022 15:45:05 +0000
Lines: 157
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-FnlcC3qmeynZMye8YOrivyq9gFKWRLxM18MAgMhfn+wmcTbjLDpekd4BPT7/XJZKd/8tVntKpSaIW2a!99BCxp/jCGXWujcngZY1GmlZxw8uHq8ZAyJp2Y9S7XpifPLojC/6SCOuoIXGOoA36C8hTLHKGhQU!mnU=
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Received-Bytes: 6159
 by: Robert Heller - Fri, 4 Nov 2022 15:45 UTC

At Fri, 4 Nov 2022 11:34:27 -0300 Luc <no@no.no> wrote:

>
> **************************
> On Fri, 4 Nov 2022 13:36:14 -0000 (UTC), Rich wrote:
>
> > Ralf Fassel <ralfixx@gmx.de> wrote:
> > > Why is proc2 *inside* proc1?
>
> > Indeed, an answer to this question is important.
>
> ************************
>
> I believe the answer is pretty obvious.
>
> It's a large proc. I need to organize everything in sub functions
> inside the function.
>
> I have been quite clear about what I need. Again:
>
> I have proc1.
>
> Inside proc1, there is proc2 and about 20 other procs.
> Then proc2 creates widgets AND it calls many other procs in the process.
> Multiple widgets may be manipulated until a decision is taken. Each one
> of them also calls a number of procs. It's all a matter of organization.
> A button in a widget calls proc3.
> Then proc 3 also calls a bunch of other procs and meanwhile it may
> or may not decide it's time for the big parent proc to return an output.
>

This sounds like you need to use wait:

proc proc2 {args} {
### create widgets here
global answer
set answer 0
button .foo -command proc3
}

proc proc3 {} {
# this is bound to button
global answer
incr answer
}

proc proc1 {args} {
proc2
global answer
vwait answer
return $answer
}

> It's all a matter of organization.

SNIT can be your friend here (see below).

>
> It's 1,900 lines of code. And yes, I'm afraid it may be a little spaghetti
> here and there. I will improve it later. But this is not the best time to post
> more code. Please consider just the description above. The entire code will be
> published eventually and I will be very open to criticism, but I can't publish
> something that doesn't work.

Why not? Someone might look at the "broken" code and suggest a fix to make it
work.

Rather then post 1,900 lines of code to a newsgroup, you might want to put it
up on GitHub and post the link here.

>
> I was almost sure someone would suggest uplevel, but nobody has and I have
> tried it on my own, it doesn't seem to work.

Uplevel is a completely different beast. The use of 'return -code ...' is the
usual way of jumping a return out-of-band. (One can also use error, with
catch or try as well and might be the only way to jump multiple levels.)

>
> The return -code return "deep thoughts" idea doesn't work either.

Then something else is going on. Are you wanting to jump multiple levels? Or
trying to do some *syncroniously* from an asyncronious event? Maybe you want
to use [tk]wait...

> The "deep thoughts" example I posted previously is too simple to reflect
> what I have here. I basically need a command that says
> STOP EVERYTHING RIGHT NOW, RETURN THIS STRING AND DISAPPEAR

What it sounds like is that you are reinventing an irregular polygonal
wheel... :-)

You can probably do all of this with SNIT. Much more cleanly and efficently
and probably with better organization.

(you need to install tcllib)

package require snit
package require Tk

snit::widget MyMegaWidget {
variable answer 0
## add more instance variables (like globals)
component button
## add more components (sub-widgets you might need to access)
delegate option -buttonlabel to button as -label
## maybe add more options
constructor {args} {
## build the mega widget
install button using button $win.button \
-command [mymethod RecordAnswer] \
-state disabled
### build more widgets
## configure everything
$self configurelist $args
}
method Run {args} {
# do some processing (be sure to call update idle from time to time)
# wait for the button
set answer 0
$button configure -state normal
tkwait variable [myvar answer]
return "The answer is 42"
}
method RecordAnswer {
# tickle the vwait above
incr answer
}
}

proc main {} {
## build the GUI
pack [MyMegaWidget .bigwidget -buttonlabel "Hit me!"]
## process pending idle events (eg exposure events, etc.)
update idle
## start the processing (note: this might actually be started by some
## GUI element, in which case the next line vanishes)
.bigwidget Run
}

main

>
>

--
Robert Heller -- Cell: 413-658-7953 GV: 978-633-5364
Deepwoods Software -- Custom Software Services
http://www.deepsoft.com/ -- Linux Administration Services
heller@deepsoft.com -- Webhosting Services

Re: How do I make a proc return the output of a sub proc?

<_K2dnWEJQJWIqvj-nZ2dnZfqn_GdnZ2d@giganews.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border-2.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-1.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Fri, 04 Nov 2022 16:00:21 +0000
MIME-Version: 1.0
From: hel...@deepsoft.com (Robert Heller)
Organization: Deepwoods Software
X-Newsreader: TkNews 3.0 (1.2.15)
Subject: Re: How do I make a proc return the output of a sub proc?
In-Reply-To: <tk3adu$14u3$1@gioia.aioe.org>
References: <20221104033658.73503ea1@lud1.home>?
<b0cf1159-1065-4eed-9d24-064c8cdc7983n@googlegroups.com>?
<20221104050646.13fd3761@lud1.home> <ygasfiz6o4v.fsf@akutech.de>?
<tk34ge$1qd54$4@dont-email.me> <20221104113427.6cf60333@lud1.home>
<tk3adu$14u3$1@gioia.aioe.org>
Newsgroups: comp.lang.tcl
Content-Type: text/plain;
charset="us-ascii"
Originator: heller@sharky4.deepsoft.com
Message-ID: <_K2dnWEJQJWIqvj-nZ2dnZfqn_GdnZ2d@giganews.com>
Date: Fri, 04 Nov 2022 16:00:21 +0000
Lines: 79
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-SN8CF99uwW7bkOlWOAkyuOXdNTzh4yA5hxlpd5h5xiwS0PfsmrROtxmYQeCqJhN6PNN9dwpg2DZV1Ae!duff7Sj9l2T8tkiH5FUMNTKPrLVLsgKYv5wE1YuPTck1BK36zI9AY2RRiEgZ5YVvZv8ueoskhRtx!Ado=
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
 by: Robert Heller - Fri, 4 Nov 2022 16:00 UTC

At Fri, 4 Nov 2022 10:17:17 -0500 Gerald Lester <Gerald.Lester@KnG-Consulting.net> wrote:

>
> On 11/4/22 09:34, Luc wrote:
> > **************************
> > On Fri, 4 Nov 2022 13:36:14 -0000 (UTC), Rich wrote:
> >
> >> Ralf Fassel <ralfixx@gmx.de> wrote:
> >>> Why is proc2 *inside* proc1?
> >
> >> Indeed, an answer to this question is important.
> >
> > ************************
> >
> > I believe the answer is pretty obvious.
> >
> > It's a large proc. I need to organize everything in sub functions
> > inside the function.
>
> Ah, you do realize that all procs are globally addressable -- there is
> no such thing as a sub function in Tcl.

You can sort of get that with OOP with member functions (eg SNIT, incrTcl,
BWidget). You can also use namespaces to "protect" things and avoid problems
with name clashes.

>
> A Tcl proc, can have another proc declared inside of it -- but that just
> causes it to be defined/redefined at runtime and it can be called by anyone.
>
> Now a Tcl proc can *call* another function, but that does not make it
> "inside" nor does it make it a aub function.

It sounds like that OP wants to create a class with "private" members (or
something like that). Tcl has OOP extensions, but I don't think any implement
strickly private (or protected) members or methods (AFAIK). (SNIT doesn't.)

>
> >...
> > The return -code return "deep thoughts" idea doesn't work either.
> > The "deep thoughts" example I posted previously is too simple to reflect
> > what I have here. I basically need a command that says
> > STOP EVERYTHING RIGHT NOW, RETURN THIS STRING AND DISAPPEAR
>
> You need to combine [info level] with [return] -- please read both
> man/help pages in detail and pay close attention to the level option on
> the return.

I suspect that this won't help either. He wants to exit a proc on a button
click. The button -command is running at level 0 and the proc is somewhere
else (or maybe already exited).

I suspect he really wants tkwait:

proc main {} {
global theanswer
## build widgets and start processing
set theanswer {}
tkwait variable theanswer
return $theanswer
}

And somewhere there is a button with a -command bound to a proc like:

proc buttonpress {} {
global theanswer
set theanswer "This is the answer"
}

>
>

--
Robert Heller -- Cell: 413-658-7953 GV: 978-633-5364
Deepwoods Software -- Custom Software Services
http://www.deepsoft.com/ -- Linux Administration Services
heller@deepsoft.com -- Webhosting Services

Re: How do I make a proc return the output of a sub proc?

<20221104134334.3c940902@lud1.home>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!ygY8GGqbXOZkGZKslZ69Yw.user.46.165.242.75.POSTED!not-for-mail
From: no...@no.no (Luc)
Newsgroups: comp.lang.tcl
Subject: Re: How do I make a proc return the output of a sub proc?
Date: Fri, 4 Nov 2022 13:43:34 -0300
Organization: Aioe.org NNTP Server
Message-ID: <20221104134334.3c940902@lud1.home>
References: <20221104033658.73503ea1@lud1.home>
<b0cf1159-1065-4eed-9d24-064c8cdc7983n@googlegroups.com>
<20221104050646.13fd3761@lud1.home>
<ygasfiz6o4v.fsf@akutech.de>
<tk34ge$1qd54$4@dont-email.me>
<20221104113427.6cf60333@lud1.home>
<OP-cnbHzc9wcrvj-nZ2dnZfqnPidnZ2d@giganews.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="42414"; posting-host="ygY8GGqbXOZkGZKslZ69Yw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Newsreader: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu)
X-Notice: Filtered by postfilter v. 0.9.2
 by: Luc - Fri, 4 Nov 2022 16:43 UTC

On Fri, 04 Nov 2022 15:45:05 +0000, Robert Heller wrote:

> This sounds like you need to use wait:
>
> proc proc2 {args} {
> ### create widgets here
> global answer
> set answer 0
> button .foo -command proc3
> }
>
> proc proc3 {} {
> # this is bound to button
> global answer
> incr answer
> }
>
>
>
> proc proc1 {args} {
> proc2
> global answer
> vwait answer
> return $answer
> }
>
************************

I suspected for some time that vwait would be the answer. But I don't know
how to use it. There are parts of Tcl that I never learned properly.

Your method with vwait kind of works.

proc bigproc {} {
...
} puts [bigproc]

The expected output prints, but the... um, application doesn't close.
That I could have achieved with puts.

The entire thing is in a proc. If it returns, it should be extinguished
immediately after printing output, shouldn't it?

--
Luc
>>

Re: How do I make a proc return the output of a sub proc?

<tk3fpi$1t16r$1@dont-email.me>

  copy mid

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

  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: ric...@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: How do I make a proc return the output of a sub proc?
Date: Fri, 4 Nov 2022 16:48:50 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 114
Message-ID: <tk3fpi$1t16r$1@dont-email.me>
References: <20221104033658.73503ea1@lud1.home> <b0cf1159-1065-4eed-9d24-064c8cdc7983n@googlegroups.com> <20221104050646.13fd3761@lud1.home> <ygasfiz6o4v.fsf@akutech.de> <tk34ge$1qd54$4@dont-email.me> <20221104113427.6cf60333@lud1.home>
Injection-Date: Fri, 4 Nov 2022 16:48:50 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="4e8ea44998da3f7d079b142bcda36cfb";
logging-data="2000091"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Jd2ToIkuk4DYqkFpv0Ffb"
User-Agent: tin/2.0.1-20111224 ("Achenvoir") (UNIX) (Linux/3.10.17 (x86_64))
Cancel-Lock: sha1:jPUxczyiYf7EMFEO2rSbi0eAKME=
 by: Rich - Fri, 4 Nov 2022 16:48 UTC

Luc <no@no.no> wrote:
> **************************
> On Fri, 4 Nov 2022 13:36:14 -0000 (UTC), Rich wrote:
>
>> Ralf Fassel <ralfixx@gmx.de> wrote:
>> > Why is proc2 *inside* proc1?
>
>> Indeed, an answer to this question is important.
>
> ************************
>
> I believe the answer is pretty obvious.

It is not. As defining a proc, inside another proc, is only rarely
done, and even then, generally for very advanced "dynamic code
generation" reasons. None of which your example, nor initial question,
implied was happening.

> It's a large proc. I need to organize everything in sub functions
> inside the function.

Except, that is not how Tcl code is parsed (nor how it is organized).

By defining a proc, inside another proc, you are repeating the
creation of that 'inner' proc every time you execute the outer proc
(which if the outer proc is executed multiple times can result in a
rather significant performance loss).

That is also not how the procs are organized once defined. Without any
namespace qualifiers, they are all created, at the same level, in the
current namespace. I.e., note below:

State, before defining any additional procs.

$ rlwrap tclsh
% info procs
auto_load_index unknown auto_import auto_execok auto_qualify auto_load history tclLog

Define a proc, that when executed, will as part of being executed
define another proc.

% proc outer {} { proc inner {} {} }

Execute the outer proc.

% outer

Note the changes to 'info procs':

% info procs
auto_load_index unknown auto_import auto_execok inner auto_qualify auto_load outer history tclLog
%

Both 'inner' and 'outer' are present at global level. The 'inner' proc
is not *inside* the outer proc.

> I have been quite clear about what I need. Again:

Maybe you find it clear. For us who have only your posting to go on,
it is very murky and confusing.

> The return -code return "deep thoughts" idea doesn't work either.
> The "deep thoughts" example I posted previously is too simple to reflect
> what I have here. I basically need a command that says
> STOP EVERYTHING RIGHT NOW, RETURN THIS STRING AND DISAPPEAR

Which is exactly what the 'code return' example I posted does. Outer
stops at the point where it called 'inner', returns the string given
back from 'inner' and disappears.

Will it work from a five level deep call stack? Not if what you want
to do is abort the first proc in the stack. For that, you likely may
need to combine both uplevel and return -code return, and count your
nesting level, and such will be fragile and subject to breakage from
making code changes.

Do do what it sounds like you want, which is:

p1 calls p2 which calls p3 which calls p4 -- p4 decides to abort all of
p1 through p3

Then your best way is to have each one return some sentinel data, and
you wrap each call with a check for the procs return sentinel data, and
if the sentinel says "abort" the check aborts and returns a further
sentinel up the stack.

Ie.

proc p1 {} {
lassign [p2] sentinel value
if {$sentinel eq "abort"} { return $value }
# other stuff done with $value here if sentinel is not "abort"
#
}

proc p2 {} {
lassign [p3] sentinel value
if {$sentinel eq "abort"} { return [list abort $value] }
# other stuff done with $value here if sentinel is not "abort"
}

proc p3 {} {
lassign [p4] sentinel value
if {$sentinel eq "abort"} { return [list abort $value] }
# other stuff done with $value here if sentinel is not "abort"
}

proc p4 {} {
if {rand() < 0.5} {
return [list abort "The string to pass up the call chain"]
}
# other stuff to do if we are not aborting the call chain
}

Re: How do I make a proc return the output of a sub proc?

<20221104135450.6cea0caa@lud1.home>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!ygY8GGqbXOZkGZKslZ69Yw.user.46.165.242.75.POSTED!not-for-mail
From: no...@no.no (Luc)
Newsgroups: comp.lang.tcl
Subject: Re: How do I make a proc return the output of a sub proc?
Date: Fri, 4 Nov 2022 13:54:50 -0300
Organization: Aioe.org NNTP Server
Message-ID: <20221104135450.6cea0caa@lud1.home>
References: <20221104033658.73503ea1@lud1.home>
<b0cf1159-1065-4eed-9d24-064c8cdc7983n@googlegroups.com>
<20221104050646.13fd3761@lud1.home>
<ygasfiz6o4v.fsf@akutech.de>
<tk34ge$1qd54$4@dont-email.me>
<20221104113427.6cf60333@lud1.home>
<tk3adu$14u3$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="56823"; posting-host="ygY8GGqbXOZkGZKslZ69Yw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Newsreader: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu)
X-Notice: Filtered by postfilter v. 0.9.2
 by: Luc - Fri, 4 Nov 2022 16:54 UTC

On Fri, 4 Nov 2022 10:17:17 -0500, Gerald Lester wrote:

> Ah, you do realize that all procs are globally addressable -- there is
> no such thing as a sub function in Tcl.

I don't understand what you mean.

proc out {} {
proc in {} {
return "deep thoughts"
}
return "shallow thoughts"
}

% puts [out]
shallow thoughts

% puts [in]
invalid command name "in"
while executing
"in"
invoked from within
"puts [in]"
(file "procproc.tcl" line 9)
Compilation failed.

proc "in" only works inside "out."
That is not my idea of "globally addressable."

> You need to combine [info level] with [return] -- please read both
> man/help pages in detail and pay close attention to the level option on
> the return.

I've been reading that already. I don't know how to use it.

[info level] outputs 1, but I don't see how that 1 can be useful.

{return $_selection} doesn't work
{return -level 0 $_selection} doesn't work
{return -level 1 $_selection} doesn't work
{return -level 2 $_selection} doesn't work
{puts $_selection; return -level 0} doesn't work
{puts $_selection; return -level 1} doesn't work
{puts $_selection; return -level 2} doesn't work

--
Luc
>>

Re: How do I make a proc return the output of a sub proc?

<jskupiFn807U1@mid.individual.net>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: ...@ednolan (ted@loft.tnolan.com (Ted Nolan)
Newsgroups: comp.lang.tcl
Subject: Re: How do I make a proc return the output of a sub proc?
Date: 4 Nov 2022 17:00:34 GMT
Organization: loft
Lines: 60
Message-ID: <jskupiFn807U1@mid.individual.net>
References: <20221104033658.73503ea1@lud1.home> <20221104113427.6cf60333@lud1.home> <tk3adu$14u3$1@gioia.aioe.org> <20221104135450.6cea0caa@lud1.home>
X-Trace: individual.net G7MW5xBEWNZr0h3VEKihWQXoBp0RjMpDU+fK4Zi6t0Wyv2DHla
X-Orig-Path: not-for-mail
Cancel-Lock: sha1:ykSeuwprFFPdMQgBZAy1hLyDOMk=
X-Newsreader: trn 4.0-test76 (Apr 2, 2001)
 by: ted@loft.tnolan.com - Fri, 4 Nov 2022 17:00 UTC

In article <20221104135450.6cea0caa@lud1.home>, Luc <no@no.no> wrote:
>On Fri, 4 Nov 2022 10:17:17 -0500, Gerald Lester wrote:
>
>> Ah, you do realize that all procs are globally addressable -- there is
>> no such thing as a sub function in Tcl.
>
>I don't understand what you mean.
>
>proc out {} {
> proc in {} {
> return "deep thoughts"
> }
> return "shallow thoughts"
>}
>
>% puts [out]
>shallow thoughts
>
>% puts [in]
>invalid command name "in"
> while executing
>"in"
> invoked from within
>"puts [in]"
> (file "procproc.tcl" line 9)
>Compilation failed.
>
>
>proc "in" only works inside "out."
>That is not my idea of "globally addressable."
>
>

I think he means this:

Create a file like:

============
#!/usr/local/bin/tclsh8.6

proc a {} {
puts "Hello from a!"

proc b {} {
puts "hello from b!"
}

}
a b
============

and run it. The output will be:

Hello from a!
hello from b!

--
columbiaclosings.com
What's not in Columbia anymore..

Re: How do I make a proc return the output of a sub proc?

<tk3haq$1tiik$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: ric...@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: How do I make a proc return the output of a sub proc?
Date: Fri, 4 Nov 2022 17:15:06 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 12
Message-ID: <tk3haq$1tiik$1@dont-email.me>
References: <20221104033658.73503ea1@lud1.home> <b0cf1159-1065-4eed-9d24-064c8cdc7983n@googlegroups.com> <20221104050646.13fd3761@lud1.home> <ygasfiz6o4v.fsf@akutech.de> <tk34ge$1qd54$4@dont-email.me> <20221104113427.6cf60333@lud1.home> <OP-cnbHzc9wcrvj-nZ2dnZfqnPidnZ2d@giganews.com> <20221104134334.3c940902@lud1.home>
Injection-Date: Fri, 4 Nov 2022 17:15:06 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="4e8ea44998da3f7d079b142bcda36cfb";
logging-data="2017876"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19OmJvVaB7aczBs1at04YDI"
User-Agent: tin/2.0.1-20111224 ("Achenvoir") (UNIX) (Linux/3.10.17 (x86_64))
Cancel-Lock: sha1:wbS9RuYRTdAyvHb0x39xy4PxVyw=
 by: Rich - Fri, 4 Nov 2022 17:15 UTC

Luc <no@no.no> wrote:
> The entire thing is in a proc. If it returns, it should be extinguished
> immediately after printing output, shouldn't it?

Not if you are running Tk.

If you are running Tk then returning from the last called proc causes
Tk to enter the event loop and wait for GUI events to trigger.

If you really want to "exit" the entire GUI, then "exit" is the command
you want. No matter where you call "exit" the entire application will
disappear.

Re: How do I make a proc return the output of a sub proc?

<tk3he5$1tiik$2@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: ric...@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: How do I make a proc return the output of a sub proc?
Date: Fri, 4 Nov 2022 17:16:53 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 47
Message-ID: <tk3he5$1tiik$2@dont-email.me>
References: <20221104033658.73503ea1@lud1.home> <b0cf1159-1065-4eed-9d24-064c8cdc7983n@googlegroups.com> <20221104050646.13fd3761@lud1.home> <ygasfiz6o4v.fsf@akutech.de> <tk34ge$1qd54$4@dont-email.me> <20221104113427.6cf60333@lud1.home> <tk3adu$14u3$1@gioia.aioe.org> <20221104135450.6cea0caa@lud1.home>
Injection-Date: Fri, 4 Nov 2022 17:16:53 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="4e8ea44998da3f7d079b142bcda36cfb";
logging-data="2017876"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19aFH7m8x8rzgGMztxRsSg5"
User-Agent: tin/2.0.1-20111224 ("Achenvoir") (UNIX) (Linux/3.10.17 (x86_64))
Cancel-Lock: sha1:FrIgaEGq6H34Ce4M3J8dlG+7eqk=
 by: Rich - Fri, 4 Nov 2022 17:16 UTC

Luc <no@no.no> wrote:
> On Fri, 4 Nov 2022 10:17:17 -0500, Gerald Lester wrote:
>
>> Ah, you do realize that all procs are globally addressable -- there is
>> no such thing as a sub function in Tcl.
>
> I don't understand what you mean.
>
> proc out {} {
> proc in {} {
> return "deep thoughts"
> }
> return "shallow thoughts"
> }
>
> % puts [out]
> shallow thoughts
>
> % puts [in]
> invalid command name "in"
> while executing
> "in"
> invoked from within
> "puts [in]"
> (file "procproc.tcl" line 9)
> Compilation failed.
>
>
> proc "in" only works inside "out."
> That is not my idea of "globally addressable."

Something is broken in your Tcl interpreter (or you did not actually
run the same code you posted):

$ rlwrap tclsh
proc out {} {
proc in {} {
return "deep thoughts"
}
return "shallow thoughts"
}
% puts [out]
shallow thoughts
% puts [in]
deep thoughts
%

Re: How do I make a proc return the output of a sub proc?

<20221104141739.22319407@lud1.home>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!ygY8GGqbXOZkGZKslZ69Yw.user.46.165.242.75.POSTED!not-for-mail
From: no...@no.no (Luc)
Newsgroups: comp.lang.tcl
Subject: Re: How do I make a proc return the output of a sub proc?
Date: Fri, 4 Nov 2022 14:17:39 -0300
Organization: Aioe.org NNTP Server
Message-ID: <20221104141739.22319407@lud1.home>
References: <20221104033658.73503ea1@lud1.home>
<b0cf1159-1065-4eed-9d24-064c8cdc7983n@googlegroups.com>
<20221104050646.13fd3761@lud1.home>
<ygasfiz6o4v.fsf@akutech.de>
<tk34ge$1qd54$4@dont-email.me>
<20221104113427.6cf60333@lud1.home>
<tk3fpi$1t16r$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="5384"; posting-host="ygY8GGqbXOZkGZKslZ69Yw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Notice: Filtered by postfilter v. 0.9.2
X-Newsreader: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu)
 by: Luc - Fri, 4 Nov 2022 17:17 UTC

On Fri, 4 Nov 2022 16:48:50 -0000 (UTC), Rich wrote:

> It is not. As defining a proc, inside another proc, is only rarely
> done, and even then, generally for very advanced "dynamic code
> generation" reasons. None of which your example, nor initial question,
> implied was happening.

Are you saying I should remove everything from its all-enveloping proc
and provide the entire idea as a plain page (though still with procs)
and let people just [source] it instead of running it as a proc?
I admit I have thought about that.

> By defining a proc, inside another proc, you are repeating the
> creation of that 'inner' proc every time you execute the outer proc
> (which if the outer proc is executed multiple times can result in a
> rather significant performance loss).

Yes, that's intended. All those procs are necessary every time the big proc
is run. The big proc won't work without them.

The big proc will not be executed multiple times. Well, it will, but not
in rapid sequence. It's a tool that people will launch occasionally.

I don't believe any of those procs is CPU or memory intensive.

I believe everything I'm doing is pretty regular except that I wrapped
the whole package in an all-encompassing proc.

For example, take /usr/share/tcltk/tk8.6/bgerror.tcl. It has seven procs.
Now put that entire page inside one parent proc. That's what I did.
Sort of. That's all.

> That is also not how the procs are organized once defined. Without any
> namespace qualifiers, they are all created, at the same level, in the
> current namespace.

That one statement is not accurate. As it turns out, EVERYTHING I'm doing
has its own namespace so nothing in it will clash with anything else in
whatever application that may come to adopt it. It's one big proc inside
one single namespace. ALL procs and variables reside in that namespace.

--
Luc
>>

Re: How do I make a proc return the output of a sub proc?

<20221104142039.3c4b78b1@lud1.home>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!ygY8GGqbXOZkGZKslZ69Yw.user.46.165.242.75.POSTED!not-for-mail
From: no...@no.no (Luc)
Newsgroups: comp.lang.tcl
Subject: Re: How do I make a proc return the output of a sub proc?
Date: Fri, 4 Nov 2022 14:20:39 -0300
Organization: Aioe.org NNTP Server
Message-ID: <20221104142039.3c4b78b1@lud1.home>
References: <20221104033658.73503ea1@lud1.home>
<20221104113427.6cf60333@lud1.home>
<tk3adu$14u3$1@gioia.aioe.org>
<20221104135450.6cea0caa@lud1.home>
<jskupiFn807U1@mid.individual.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="5384"; posting-host="ygY8GGqbXOZkGZKslZ69Yw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Notice: Filtered by postfilter v. 0.9.2
X-Newsreader: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu)
 by: Luc - Fri, 4 Nov 2022 17:20 UTC

**************************
On 4 Nov 2022 17:00:34 GMT, ted@loft.tnolan.com (Ted Nolan ) wrote:

> I think he means this:
>
> Create a file like:
>
> ============
> #!/usr/local/bin/tclsh8.6
>
> proc a {} {
> puts "Hello from a!"
>
> proc b {} {
> puts "hello from b!"
> }
>
> }
> a
> b
> ============
>
> and run it. The output will be:
>
> Hello from a!
> hello from b!

Yes, because [puts] has a way of piercing through armour.

Now, if only I could do that with [return]...

--
Luc
>>

Re: How do I make a proc return the output of a sub proc?

<20221104142826.0d9ffd93@lud1.home>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!ygY8GGqbXOZkGZKslZ69Yw.user.46.165.242.75.POSTED!not-for-mail
From: no...@no.no (Luc)
Newsgroups: comp.lang.tcl
Subject: Re: How do I make a proc return the output of a sub proc?
Date: Fri, 4 Nov 2022 14:28:26 -0300
Organization: Aioe.org NNTP Server
Message-ID: <20221104142826.0d9ffd93@lud1.home>
References: <20221104033658.73503ea1@lud1.home>
<b0cf1159-1065-4eed-9d24-064c8cdc7983n@googlegroups.com>
<20221104050646.13fd3761@lud1.home>
<ygasfiz6o4v.fsf@akutech.de>
<tk34ge$1qd54$4@dont-email.me>
<20221104113427.6cf60333@lud1.home>
<tk3adu$14u3$1@gioia.aioe.org>
<20221104135450.6cea0caa@lud1.home>
<tk3he5$1tiik$2@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="5384"; posting-host="ygY8GGqbXOZkGZKslZ69Yw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Notice: Filtered by postfilter v. 0.9.2
X-Newsreader: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu)
 by: Luc - Fri, 4 Nov 2022 17:28 UTC

**************************
On Fri, 4 Nov 2022 17:16:53 -0000 (UTC), Rich wrote:

> Something is broken in your Tcl interpreter (or you did not actually
> run the same code you posted):
>
> $ rlwrap tclsh
> proc out {} {
> proc in {} {
> return "deep thoughts"
> }
> return "shallow thoughts"
> }
> % puts [out]
> shallow thoughts
> % puts [in]
> deep thoughts
> %

True.

I think I ran it the other way around:

puts [in]
puts [out]

--
Luc
>>

Re: How do I make a proc return the output of a sub proc?

<tk3ifh$17ku$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!a5rWVvs5S5ZXUwkNcVnRMw.user.46.165.242.75.POSTED!not-for-mail
From: saitolo...@gmail.com (saitology9)
Newsgroups: comp.lang.tcl
Subject: Re: How do I make a proc return the output of a sub proc?
Date: Fri, 4 Nov 2022 13:34:39 -0400
Organization: Aioe.org NNTP Server
Message-ID: <tk3ifh$17ku$1@gioia.aioe.org>
References: <20221104033658.73503ea1@lud1.home>
<20221104113427.6cf60333@lud1.home> <tk3adu$14u3$1@gioia.aioe.org>
<20221104135450.6cea0caa@lud1.home> <jskupiFn807U1@mid.individual.net>
<20221104142039.3c4b78b1@lud1.home>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="40606"; posting-host="a5rWVvs5S5ZXUwkNcVnRMw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.3.2
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: saitology9 - Fri, 4 Nov 2022 17:34 UTC

On 11/4/2022 1:20 PM, Luc wrote:

>>
>> and run it. The output will be:
>>
>> Hello from a!
>> hello from b!
>
>
> Yes, because [puts] has a way of piercing through armour.
>
> Now, if only I could do that with [return]...
>

Your inlined example and file-d versions are both identical in their
effects. If you call [in] first, you will get an error. [puts] does
nothing special here. You can just issue "in" and "out" at the prompt.

What is relevant for the point here is that, the inner proc is not
defined until the outer proc is called at least once. It then creates
the inner proc, which then becomes available to call.

Call sequence must be in that order.

Re: How do I make a proc return the output of a sub proc?

<UTednRITD-XC0Pj-nZ2dnZfqn_adnZ2d@giganews.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.iad1.usenetexpress.com!69.80.99.23.MISMATCH!Xl.tags.giganews.com!local-2.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Fri, 04 Nov 2022 17:35:27 +0000
MIME-Version: 1.0
From: hel...@deepsoft.com (Robert Heller)
Organization: Deepwoods Software
X-Newsreader: TkNews 3.0 (1.2.15)
Subject: Re: How do I make a proc return the output of a sub proc?
In-Reply-To: <20221104134334.3c940902@lud1.home>
References: <20221104033658.73503ea1@lud1.home>??<b0cf1159-1065-4eed-9d24-064c8cdc7983n@googlegroups.com>??<20221104050646.13fd3761@lud1.home>??<ygasfiz6o4v.fsf@akutech.de>??<tk34ge$1qd54$4@dont-email.me>??<20221104113427.6cf60333@lud1.home>??<OP-cnbHzc9wcrvj-nZ2dnZfqnPidnZ2d@giganews.com> <20221104134334.3c940902@lud1.home>
Newsgroups: comp.lang.tcl
Content-Type: text/plain; charset="us-ascii"
Originator: heller@sharky4.deepsoft.com
Message-ID: <UTednRITD-XC0Pj-nZ2dnZfqn_adnZ2d@giganews.com>
Date: Fri, 04 Nov 2022 17:35:27 +0000
Lines: 75
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-B8eOwhclZzdckMtFxo7qflqQzw4S4dVylgM4YUXGcFK7NHs/Pur12wFeMCOxTCt1wS+UTX8zeh3YS8v!AAkXppL19Y4wI7n+0cDi1YbAvL4ulEK1la5UY/iDkkyU+rY3emkiPh4r+vs/Fh42KBDXpVFvfa6x!s7o=
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Received-Bytes: 3516
 by: Robert Heller - Fri, 4 Nov 2022 17:35 UTC

At Fri, 4 Nov 2022 13:43:34 -0300 Luc <no@no.no> wrote:

>
> On Fri, 04 Nov 2022 15:45:05 +0000, Robert Heller wrote:
>
> > This sounds like you need to use wait:
> >
> > proc proc2 {args} {
> > ### create widgets here
> > global answer
> > set answer 0
> > button .foo -command proc3
> > }
> >
> > proc proc3 {} {
> > # this is bound to button
> > global answer
> > incr answer
> > }
> >
> >
> >
> > proc proc1 {args} {
> > proc2
> > global answer
> > vwait answer
> > return $answer
> > }
> >
> ************************
>
> I suspected for some time that vwait would be the answer. But I don't know
> how to use it. There are parts of Tcl that I never learned properly.
>
> Your method with vwait kind of works.
>
> proc bigproc {} {
> ...
> }
> puts [bigproc]
>
> The expected output prints, but the... um, application doesn't close.
> That I could have achieved with puts.
>
> The entire thing is in a proc. If it returns, it should be extinguished
> immediately after printing output, shouldn't it?

No. Wish (or package require Tk), does not "exit" upon EOF on the .tcl file.
It does not exit until either the exit command is invoked or the main toplevel
(.) is destroyed. So, what you really want bound to your "exit" button is:

proc exitButton {} {
# print the answer
puts "This is the answer"
# then exit
exit
}

Or with a pure GUI environment (with no console screen or shell window):

proc exitButton {} {
# put up a message dialog box.
tk_messageBox -icon info -message "This is the answer" -type ok
# when the user clicks OK, exit the program.
exit
}

>

--
Robert Heller -- Cell: 413-658-7953 GV: 978-633-5364
Deepwoods Software -- Custom Software Services
http://www.deepsoft.com/ -- Linux Administration Services
heller@deepsoft.com -- Webhosting Services

Pages:12
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor