By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,473 Members | 3,657 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,473 IT Pros & Developers. It's quick & easy.

any chance we will get tail calls in C# 4.0?

P: n/a
A tail call is a way of removing the current method from the stack
before recursing. See http://blogs.msdn.com/shrib/archive/...25/360370.aspx
.. I would love to see it in C# 4.0 and wouldn't mind if we needed a
special keyword to make it happen.
Nov 6 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Thu, 06 Nov 2008 10:30:52 -0800, not_a_commie <no********@gmail.com>
wrote:
A tail call is a way of removing the current method from the stack
before recursing. See
http://blogs.msdn.com/shrib/archive/...25/360370.aspx
. I would love to see it in C# 4.0 and wouldn't mind if we needed a
special keyword to make it happen.
I doubt you'd see that. Tail recursion is so trivially implemented as a
plain iterative loop, I can't imagine that such a feature would meet the
bar for inclusion in the language.

I see why MSIL might have "tail" for supporting functional languages, but
this doesn't seem like something that needs to be exposed in C#. Any code
that could take advantage of it really just should be written differently
anyway.

Pete
Nov 6 '08 #2

P: n/a
Peter Duniho wrote:
On Thu, 06 Nov 2008 10:30:52 -0800, not_a_commie
<no********@gmail.comwrote:
>A tail call is a way of removing the current method from the stack
before recursing. See
http://blogs.msdn.com/shrib/archive/...25/360370.aspx
. I would love to see it in C# 4.0 and wouldn't mind if we needed a
special keyword to make it happen.

I doubt you'd see that. Tail recursion is so trivially implemented
as a plain iterative loop, I can't imagine that such a feature would
meet the bar for inclusion in the language.
I think more generally, switch/goto case (there's no requirement that the
tail call has to be recursion back to the same function, all participating
functions would have to be combined and turned into different case blocks in
a single master function).
>
I see why MSIL might have "tail" for supporting functional languages,
but this doesn't seem like something that needs to be exposed in C#. Any
code that could take advantage of it really just should be
written differently anyway.

Pete

Nov 6 '08 #3

P: n/a
"not_a_commie" <no********@gmail.comwrote in message
news:21**********************************@r37g2000 prr.googlegroups.com...
>A tail call is a way of removing the current method from the stack
before recursing. See
http://blogs.msdn.com/shrib/archive/...25/360370.aspx
. I would love to see it in C# 4.0 and wouldn't mind if we needed a
special keyword to make it happen.

This should be a compiler optimization as it's very easy to detect and even
easier to implement once detected.

Mike.
Nov 6 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.