Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tail recursion behaviour is unspecified #1219

Closed
scabug opened this issue Aug 13, 2008 · 6 comments · Fixed by scala/scala#10566
Closed

Tail recursion behaviour is unspecified #1219

scabug opened this issue Aug 13, 2008 · 6 comments · Fixed by scala/scala#10566

Comments

@scabug
Copy link

scabug commented Aug 13, 2008

The word "tail" appears only twice in the SLS, both as method names in example 5.3.3. So it appears that the current (rather delicate!) behaviour of tail recursion is in fact a completely unspecified feature. It would be nice if this could be fixed. :-)

@scabug
Copy link
Author

scabug commented Aug 13, 2008

Imported From: https://issues.scala-lang.org/browse/SI-1219?orig=1
Reporter: @DRMacIver

@scabug
Copy link
Author

scabug commented Mar 16, 2009

@paulp said:
A note for when/if this is specified, as of r17315 there is a @tailrec annotation.

@nogurenn
Copy link

nogurenn commented Sep 3, 2019

Does this still hold true for the current versions?

@SethTisue
Copy link
Member

@nogurenn if you have a look yourself and find out one way or the other, let us know

@eed3si9n
Copy link
Member

The word "tail" appears only twice in the SLS

$ rg "\btail" .
02-identifiers-names-and-scopes.md
114:object X { type T = annotation.tailrec }
115:object Y { type T = annotation.tailrec }
117:  import X._, Y._, annotation.{tailrec => T}  // OK, all T mean tailrec
118:  @T def f: Int = { f ; 42 }                  // error, f is not tail recursive

07-implicits.md
107:  else m.add(xs.head, sum(xs.tail))

05-classes-and-objects.md
833:  var tail: LinkedList[A] = null
835:  def this(head: A, tail: LinkedList[A]) = { this(head); this.tail = tail }
841:third one constructs a list with a given head and tail.

The word "tail" appears 7 times, one of which as "tail recursive", and tailrec appears 4 times, used as a weird example of import renaming. The tail recursion in general continues to be unspecified.

@som-snytt
Copy link

The weird example is tweaked in https://github.com/scala/scala/pull/10162/files (Tweaked not for weirdness but correctness: rename on import is higher precedence than wildcard, undermining the point of the example.)

I will supply doc in the annotations section for tailrec and switch. (I also went looking for it.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants