Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Is it safe for stack?

0 views
Skip to first unread message

ZB

unread,
Oct 11, 2008, 11:21:41 AM10/11/08
to
I mean the quite often (as I see) used construction of the type:

proc eventLoop {} {
...
after 100 eventLoop
}

Seems to me very recursion-like, and I'm wondering, will it cause
overflow in the end?
--
ZB

Helmut Giese

unread,
Oct 11, 2008, 12:13:22 PM10/11/08
to
> proc eventLoop {} {
> ...
> after 100 eventLoop
> }
>
>Seems to me very recursion-like, and I'm wondering, will it cause
>overflow in the end?
Hi ZB,
no recursion there. Here is what happens:
proc eventLoop {} {
...
(t1) after 100 eventLoop
(t2) }

At time t1 the statement
after 100 eventLoop
is executed which arranges for 'eventLoop' to be called again at time
't3 = t1 + 100 ms'.
At time t2 (some microseconds after t1) the current invocation of
'eventLoop' is terminated and your app is now free to respond to other
events (button clicks, read events, whatever).

At time t3 'eventLoop' is invoked again (or a bit later if at that
particular moment your app is already busy processing another event),
and the scenario is repeated.

You would have recursion if you had a proc like
proc recurse {} {
...
recurse
}
where 'recurse' is _called directly_ - understand the difference
between _calling_ a proc and _arranging_ for a proc to be called at a
certain moment in the future.

HTH
Helmut Giese

ZB

unread,
Oct 11, 2008, 12:16:53 PM10/11/08
to
Dnia 11.10.2008 Helmut Giese <hgi...@ratiosoft.com> napisał/a:

> understand the difference
> between _calling_ a proc and _arranging_ for a proc to be called at a
> certain moment in the future.

Thanks, you're right - confused "after" with kind of "delay" or "pause".
--
ZB

Cameron Laird

unread,
Oct 11, 2008, 12:35:18 PM10/11/08
to
In article <slrngf1h45.605...@sarge.my.own.domain.no-net>,
.
.
.
No.

We'll eventually follow-up with details,
explanations of how it could seem to do
so, and other matters. Briefly, though:
"no".

Helmut Giese

unread,
Oct 11, 2008, 1:22:28 PM10/11/08
to
On 11 Oct 2008 16:16:53 GMT, ZB <zbREMOVE_THIS@AND_THISispid.com.pl>
wrote:

Hm,
this sounds to me like there might be some confusion left: 'after'
_can_ also mean 'pause'.
Consider this modification to your original example:

proc eventLoop {} {
...
(t1) after 100

(t2) eventLoop
}

At t1 an unconditional wait is started - your app will do nothing (not
even respond to other events) for 100 ms.
At t2 (== t1 + 100 ms) it will recurse.

Have a look at after's man page.
HTH
Helmut Giese

ZB

unread,
Oct 11, 2008, 1:40:47 PM10/11/08
to
Dnia 11.10.2008 Helmut Giese <hgi...@ratiosoft.com> napisał/a:

> Have a look at after's man page.

Hmmm... I think, the better solution would be separate, special "wait
command" (wait, delay, sleep... whatever) - instead of "overloading" `after'.

Of course, too late now.
--
ZB

Les Cargill

unread,
Oct 11, 2008, 2:29:52 PM10/11/08
to

it's not overloading - "after" installs a callback on an
opaque timer chain, regardless of context.

"Opaque" in that you can't see it except through its abstraction.

--
Les Cargill

Robert Heller

unread,
Oct 11, 2008, 2:54:05 PM10/11/08
to
At 11 Oct 2008 16:16:53 GMT ZB <zbREMOVE_THIS@AND_THISispid.com.pl> wrote:

>
> Dnia 11.10.2008 Helmut Giese <hgi...@ratiosoft.com> napisa³/a:


>
> > understand the difference
> > between _calling_ a proc and _arranging_ for a proc to be called at a
> > certain moment in the future.
>
> Thanks, you're right - confused "after" with kind of "delay" or "pause".

After with *one* argument *is* a 'kind of "delay" or "pause"'.


--
Robert Heller -- Get the Deepwoods Software FireFox Toolbar!
Deepwoods Software -- Linux Installation and Administration
http://www.deepsoft.com/ -- Web Hosting, with CGI and Database
hel...@deepsoft.com -- Contract Programming: C/C++, Tcl/Tk

David Gravereaux

unread,
Oct 12, 2008, 5:38:07 PM10/12/08
to


proc QueueAnother {when what} {
after $when $what
}

proc thisProc {} {
return [dict get [info frame -1] proc]
}

proc eventLoop {} {
...
QueueAnother 100 [thisProc]
}


Is that more readable?

ZB

unread,
Oct 14, 2008, 7:27:40 PM10/14/08
to
Dnia 12.10.2008 David Gravereaux <davy...@pobox.com> napisał/a:

> Is that more readable?

Yes, I'm aware, that I'm able to rename available functions on my own. But
such solution has its limit: it'll be readable for me, but not necessarily
for the others, for those using "common" syntax. And, from the other side,
if I'll be using "my own version of TCL", I won't feel comfortable looking
at the "common syntax" listing.

In conclusion: one has to live with that, I'm afraid. At least some time.
--
ZB

David Gravereaux

unread,
Oct 14, 2008, 8:10:30 PM10/14/08
to


Making your own procs isn't creating your own version of Tcl. On the
other hand, using stuff like tcllib's uevent
<http://tcllib.sourceforge.net/doc/uevent.html> is what people do get
interfaces to a more palatable level one can use more freely. Although
not exactly the interface you are looking for, make your own. Don't
forget the comments and do your best to make it readable.

By restricting yourself from "overloading" you've lost the entire
concept of how to simplify and customize interfaces.

0 new messages