Issue #12543 has been updated by duerst (Martin D=FCrst).


I don't think tail call optimization should be a feature that is switched o=
n or off by the programmer at each location. I think it should be an option=
 used on execution, and it should be ON by default.

We want programs to be fast, and tail call optimization makes them faster. =
In #6602, there was the opinion that tail calls are rare in Ruby, but that =
may also have to do with the fact that they are not optimized. So to some e=
xtent, it's a chicken and egg problem.

What usually happens is that users write programs and run them. If they run=
 faster, that's good. That's why I think tail call optimization should be o=
n by default. What happens next is that occasionally, there's a bug. That b=
ug may produce a stack trace. The stack trace should include a hint as to w=
here tail call optimization was in effect. The programmer will read the sta=
ck trace, and if they suspect that the bug is somewhere near the tail call,=
 they can run the program with tail calls switched off by using an option.

For me, having tail calls off by default, or having syntax to switch them o=
n per calling location seems to put the chart before the horse. I hope this=
 can be avoided.



----------------------------------------
Feature #12543: explicit tail call syntax: foo() then return
https://bugs.ruby-lang.org/issues/12543#change-81354

* Author: mame (Yusuke Endoh)
* Status: Assigned
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: =

----------------------------------------
How about introducing a new syntax for tail call?

```
def foo()
  foo()
end
foo() #=3D> stack level too deep
```

```
def bar()
  bar() then return
end
bar() #=3D> infinite loop
```

* no new keyword (cf. `goto foo()`)
* no conflict with any existing syntax
* an experimental patch is available (attached)
* no shift/reduce nor reduce/reduce conflict in parse.y

-- =

Yusuke Endoh <mame / ruby-lang.org>

---Files--------------------------------
then_return.patch (9.18 KB)


-- =

https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=3Dunsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>