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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • not_a_commie

    #1

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

    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.
  • Peter Duniho

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

    On Thu, 06 Nov 2008 10:30:52 -0800, not_a_commie <notacommie@gma il.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

    Comment

    • Ben Voigt [C++ MVP]

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

      Peter Duniho wrote:
      On Thu, 06 Nov 2008 10:30:52 -0800, not_a_commie
      <notacommie@gma il.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

      Comment

      • Michael D. Ober

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

        "not_a_comm ie" <notacommie@gma il.comwrote in message
        news:216e1a14-8e20-4ab3-bf39-4d58c4d4704d@r3 7g2000prr.googl egroups.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.


        Comment

        Working...