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

Have you seen any promises (like in javascript) implementation for Tcl?

222 views
Skip to first unread message

rildo

unread,
Aug 12, 2015, 4:01:51 PM8/12/15
to
Promises are a concept to invert the control of callback trees (callback hell) and linearize it. Suppose you are going to do some input/output from files or network and after that result, in an async way (callbacks), will look for something in the result and do some more I/O, and look for the data fetched and... (you know what I mean)

After some callbacks, your code will be "spaghetti-like" full of event called functions. Except if you use "promises". I'm not able to find a promises implementation for Tcl. As we have lambda and other functional goodies available, it would not be so difficult to implement such a thing.

If you know something already done, please let me know.

https://en.wikipedia.org/wiki/Futures_and_promises - some theory

http://documentup.com/kriskowal/q/ - a famous implementation for javascript

Some frameworks like AngularJS (http://angularjs.org) are promises-ready.

Rich

unread,
Aug 12, 2015, 4:12:15 PM8/12/15
to
rildo <rpra...@gmail.com> wrote:
> Promises are a concept to invert the control of callback trees
> (callback hell) and linearize it. Suppose you are going to do some
> input/output from files or network and after that result, in an async
> way (callbacks), will look for something in the result and do some
> more I/O, and look for the data fetched and... (you know what I mean)

> ...
The TclLib comm library has a 'future' object within it. According to
the wikipedia page you cite, futures and promises are very closely
interrelated. So maybe you might start looking there for inspiration.

miguel.sofer

unread,
Aug 13, 2015, 7:55:54 AM8/13/15
to
A different way to "linearize" the code is using coroutines, which are
available since Tcl8.6.

sled...@gmail.com

unread,
Aug 13, 2015, 10:24:58 AM8/13/15
to
Have read the Promises wiki explanation...

We have used 'after', 'trace' and arrays in order to implement a somewhat 'promises' language construct.

When ?conditions: then ?script.

Whenever ?conditions: then ?script

As implemented, the "futures" statements are the script. Any change in data, or call backs from widgets are evaluated in the context of these When/Whenever procedures.

So no spaghetti callback.



sled...@gmail.com

unread,
Aug 13, 2015, 10:49:09 AM8/13/15
to
Have read the Promises wiki explanation...

We have used 'after', 'trace' and arrays in order to implement a somewhat 'promises' language construct.

In fact, there seems (to me) to be nothing in that wiki that can't be done in a somewhat straight forward way with tcl.

To wit:

When ?conditions: then ?script.

Whenever ?conditions: then ?script

As implemented, the "futures" statements are the script. Any change in data, or call backs from widgets are evaluated in the context of these When/Whenever procedures.

So no spaghetti callback.

A 'future' statement that is part of a When construct is executed only once.
A 'future' statement that is part of a Whenever construct is executed each time that the condition is met.

It is used as part of our speech rec application.

Whenever the Agent says "May I have your credit card number" -
If asked_previously, then:
TTS says "You already asked me for my credit card once, but here it is again."
End of If
End of Whenever

When Agent enters his_age or his_age is greater than 21 -
Calculate all_ages as $his_age + $my_age
End of When

This construct eliminates the need for the inline script to evaluate every verbal or haptic response. If the conditions are not met or even present, the callback is passed on as it would ordinarily.

The conditions (promises) and response (futures) are posited in advance.
The after can be used to implement or destroy a promise

And remember...it's simply a matter of time...and that is a human construct...

Andreas Kupries

unread,
Oct 10, 2015, 4:08:41 AM10/10/15
to
The relevant part of the documentation is

http://core.tcl.tk/tcllib/doc/trunk/embedded/www/tcllib/files/modules/comm/comm.html#16

--
So long,
Andreas Kupries <akup...@shaw.ca>
<http://core.tcl.tk/akupries/>
Developer @ HP Enterprise

Tcl'2015, Oct 19-23, Manassas, VA, USA, http://www.tcl.tk/community/tcl2015/
-------------------------------------------------------------------------------

pal...@yahoo.com

unread,
Jan 31, 2016, 1:30:20 AM1/31/16
to
0 new messages