[Proposal] Add Scala-like @tailrec annotation for recursive fns

74 views
Skip to first unread message

vmrc

unread,
Jun 15, 2022, 6:08:28 PM6/15/22
to elixir-lang-core
Scala has a handy @tailrec annotation that makes the compiler error out if the function is not amenable to tail call optimization. One possible footgun while learning Elixir and recursion is trying to implement a tail-recursive fn and realizing when the stack blows up that you haven't in fact succeeded. This annotation would serve as a safeguard.

Adam Lancaster

unread,
Jun 15, 2022, 6:18:35 PM6/15/22
to elixir-l...@googlegroups.com
Do you have an example of a function that caused the stack to blow up?

Best
Adam

On Wed, 15 Jun 2022 at 23:08, 'vmrc' via elixir-lang-core <elixir-l...@googlegroups.com> wrote:
Scala has a handy @tailrec annotation that makes the compiler error out if the function is not amenable to tail call optimization. One possible footgun while learning Elixir and recursion is trying to implement a tail-recursive fn and realizing when the stack blows up that you haven't in fact succeeded. This annotation would serve as a safeguard.

O conteúdo desta mensagem é confidencial e destinado exclusivamente aos destinatários. Caso a receba por engano, favor destruí-la e notificar o remetente de imediato. O correio eletrônico não configura meio seguro para transmissão de dados e o remetente NÃO se responsabiliza por eventual erro, atraso, extravio, interceptação ou infecção por vírus. Cabe ao destinatário solicitar versão física sempre que necessário.
 
The content of this message is confidential and was intended solely to its recipient. 
In case this message is received by mistake, please destroy it and notify the sender immediately. Electronic mails are not a safe channel for data transmission and the sender accepts NO liability for eventual errors, delays, loss, interception or virus infection. When necessary, the receiver must request a hard-copy version.

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/f02e06bf-a9ab-482b-b5de-1b11a8cdb9d8n%40googlegroups.com.

Generic Jam

unread,
Jun 15, 2022, 6:22:38 PM6/15/22
to elixir-l...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages