bug icon indicating copy to clipboard operation
bug copied to clipboard

Tail recursion behaviour is unspecified

Open scabug opened this issue 17 years ago • 6 comments

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 avatar Aug 13 '08 14:08 scabug

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

scabug avatar Aug 13 '08 14:08 scabug

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

scabug avatar Mar 16 '09 17:03 scabug

Does this still hold true for the current versions?

nogurenn avatar Sep 03 '19 04:09 nogurenn

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

SethTisue avatar Jan 30 '20 22:01 SethTisue

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.

eed3si9n avatar Jan 31 '20 00:01 eed3si9n

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.)

som-snytt avatar Sep 28 '22 22:09 som-snytt