[[Proposa]] Nested functions

49 views
Skip to first unread message

ma...@lamarciana.com

unread,
Aug 2, 2017, 4:03:15 AM8/2/17
to elixir-lang-core
I don't know what would be the cost of it during compilation time or how difficult would be to implement it, but at first sight I think it could be a nice idea to allow defining functions inside other function bodies. Just like in Scala (https://www.scala-lang.org/old/node/116.html), nested functions would be in scope only for parent functions.

I think it would improve readability to be able to encapsulate those "def do_work" functions within its related "def work" function. Maybe, to avoid crazy things, we could limit the allowed nesting deep to just 2.

Andrea Leopardi

unread,
Aug 2, 2017, 5:23:40 AM8/2/17
to elixir-l...@googlegroups.com
You can achieve this today by using anonymous functions and calling them if you do not want to use a defp.

On Wed, 2 Aug 2017 at 09:03, <ma...@lamarciana.com> wrote:
I don't know what would be the cost of it during compilation time or how difficult would be to implement it, but at first sight I think it could be a nice idea to allow defining functions inside other function bodies. Just like in Scala (https://www.scala-lang.org/old/node/116.html), nested functions would be in scope only for parent functions.

I think it would improve readability to be able to encapsulate those "def do_work" functions within its related "def work" function. Maybe, to avoid crazy things, we could limit the allowed nesting deep to just 2.

--
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/5c89cded-89a6-4ea5-befd-039d391c879b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--

Andrea Leopardi

ma...@lamarciana.com

unread,
Aug 2, 2017, 5:53:13 AM8/2/17
to elixir-lang-core
Yes, but there is a limitation because the anonymous function have to be defined before its invocation, being less readable that scoped functions, in my view :)
Reply all
Reply to author
Forward
0 new messages