From: duerst@...
Date: 2019-09-02T07:06:10+00:00
Subject: [ruby-core:94736] [Ruby master Feature#12543] explicit tail call syntax: foo() then return

Issue #12543 has been updated by duerst (Martin D�rst).


I don't think tail call optimization should be a feature that is switched on 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 extent, 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 on by default. What happens next is that occasionally, there's a bug. That bug may produce a stack trace. The stack trace should include a hint as to where tail call optimization was in effect. The programmer will read the stack 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 on 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() #=> stack level too deep
```

```
def bar()
  bar() then return
end
bar() #=> 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=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>