Goto or coroutines close to automatons

61 views
Skip to first unread message

Yannick Duchêne

unread,
Apr 9, 2015, 10:16:27 AM4/9/15
to ats-lan...@googlegroups.com
As far I know, and according to this newsgroup, ATS2 does not have the goto statement I though about to implement coroutines. The coroutines I have in mind do not invoke recursive functions (although they invoke functions), only iteration (terminal recursion, not the same as general recursion), and a discrete value would be enough to determine the point where to resume (that's why I though about goto), beside a reference to the coroutines data, which would be a linear type.

Out of curiosity, as I believe coroutines may help me in some ways, is there a way to help supporting coroutine with no general recursion? The latter point implies obviously bounded an even fixed allocation, which is important, as it makes a coroutine implementation easier. Finally, a kind of coroutine which is very close to an automaton (with some differences).

I though about automated rewriting, but what I had in mind, involves goto.

For now, this question is just a prospective question, and I though it may interest future ATS2 users too.

Yannick Duchêne

unread,
Apr 10, 2015, 9:24:06 AM4/10/15
to ats-lan...@googlegroups.com
I should have asked this question instead: is ATS guaranteed to optimize self tail calls only or all tail calls?

Brandon Barker

unread,
Apr 10, 2015, 9:30:23 AM4/10/15
to ats-lang-users
I don't have much experience with coroutines ... so i'm not sure if the example posted on the google group a couple of years ago was any use (see "leak my coroutine"). In ATS there is a way to have mutual tail call optimization http://www.cs.bu.edu/~hwxi/ATS/DOCUMENT/TUTORIALATS/HTML/c244.html

On Fri, Apr 10, 2015 at 9:24 AM, 'Yannick Duchêne' via ats-lang-users <ats-lan...@googlegroups.com> wrote:
I should have asked this question instead: is ATS guaranteed to optimize self tail calls only or all tail calls?

--
You received this message because you are subscribed to the Google Groups "ats-lang-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ats-lang-user...@googlegroups.com.
To post to this group, send email to ats-lan...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/ats-lang-users/ba812efd-49ad-40a7-a7ac-51cdfebea386%40googlegroups.com.



--
Brandon Barker
brandon...@gmail.com

gmhwxi

unread,
Apr 10, 2015, 10:18:06 AM4/10/15
to ats-lan...@googlegroups.com

Only self tail-calls by default.

To turn mutually recursive tail-calls into jumps, you need to use the keyword 'fnx' (instead of 'fun').

To turn all tail-calls into jumps, one usually needs to do CPS-style compilation.

Yannick Duchêne

unread,
Apr 10, 2015, 11:31:22 AM4/10/15
to ats-lan...@googlegroups.com


Le vendredi 10 avril 2015 16:18:06 UTC+2, gmhwxi a écrit :

Only self tail-calls by default.

To turn mutually recursive tail-calls into jumps, you need to use the keyword 'fnx' (instead of 'fun').

I did not knew `fnx`, thanks for the notice.

To turn all tail-calls into jumps, one usually needs to do CPS-style compilation.
 
If something is written in this style, how well do ATS support it?

Yannick Duchêne

unread,
Apr 10, 2015, 11:33:22 AM4/10/15
to ats-lan...@googlegroups.com


Le vendredi 10 avril 2015 16:18:06 UTC+2, gmhwxi a écrit :

Only self tail-calls by default.

To turn mutually recursive tail-calls into jumps, you need to use the keyword 'fnx' (instead of 'fun').

(I forgot a question) Why is this not the default? Is there a technical/stability reason? 

Hongwei Xi

unread,
Apr 10, 2015, 11:53:16 AM4/10/15
to ats-lan...@googlegroups.com
The original design is this:

Using 'fnx' means to require all the recursive calls in the body of the defined
function to be tail-calls. It is yet to be fully enforced.

--
You received this message because you are subscribed to the Google Groups "ats-lang-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ats-lang-user...@googlegroups.com.
To post to this group, send email to ats-lan...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.

Hongwei Xi

unread,
Apr 10, 2015, 12:04:34 PM4/10/15
to ats-lan...@googlegroups.com

>>If something is written in this style, how well do ATS support it?

There is currently no support for it in ATS.

If you are interested, you could think of a way to recompile the C code
generated from ATS source.


--
You received this message because you are subscribed to the Google Groups "ats-lang-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ats-lang-user...@googlegroups.com.
To post to this group, send email to ats-lan...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.

Yannick Duchêne

unread,
Apr 10, 2015, 2:13:27 PM4/10/15
to ats-lan...@googlegroups.com


Le vendredi 10 avril 2015 17:53:16 UTC+2, gmhwxi a écrit :
The original design is this:

Using 'fnx' means to require all the recursive calls in the body of the defined
function to be tail-calls. It is yet to be fully enforced.

I like this idea in general, to underline noticeable cases with specific keywords or syntax.

Reply all
Reply to author
Forward
0 new messages