# Nested do blocks?

**URL:** <https://discourse.julialang.org/t/nested-do-blocks/132883>\
**Category:** Internals & Design\
**Created:** [October 5, 2025, 8:01am UTC](https://discourse.julialang.org/t/nested-do-blocks/132883 "2025-10-05T08:01:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mraic1](https://avatars.discourse-cdn.com/v4/letter/m/6bbea6/32.png) [@mraic1](https://discourse.julialang.org/u/mraic1)\
**Post date:** [October 5, 2025, 8:01am UTC](https://discourse.julialang.org/t/nested-do-blocks/132883/1 "2025-10-05T08:01:40Z")

</div>

Dear developers,

While learning Julia, one of the constructions that I found particularly marvellous is the `do` block. As comprehensions and `where` expressions can be nested, wouldn’t it make sense also to allow it for the `do` blocks? One possible solution could be that, for example, the code

```julia-auto
function oe(f, g)
    f("oo")
    g("ee")
end

oe() do e
    println("g", e)
end do o
    println("f", o)
end

```

would produce

```julia-auto
foo
gee

```

Thus, as suggested above, the addition of the functions defined by the `do` blocks to the beginning of the argument list would work from the inside out; I find this solution natural, though the opposite direction producing

```julia-auto
goo
fee

```

might be more programmer-friendly.

I am aware that such an idea might already have appeared, possibly several times. 🙂 I should also be grateful for an explanation why nested `do` blocks are not a good idea.

Thank you very much for your time!

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [October 5, 2025, 8:36am UTC](https://discourse.julialang.org/t/nested-do-blocks/132883/2 "2025-10-05T08:36:56Z")

</div>

> [@mraic1](#):
>
> ```julia-auto
> oe() do e
> println("g", e)
> end do o
> println("f", o)
> end
> 
> ```

I’m not a developer, but this isn’t nesting, it’s a sequence of `do` blocks. You even lower it to a sequence of anonymous functions as inputs. The purpose of the `do` block is to shift a large first argument to the tail of a higher-order function call so we don’t have to scroll to see how many inputs it has. A sequence of large definitions like this would defeat that purpose, and a `let` block making some temporary input variables for the call would be far easier to read.

```julia-auto
julia> let
         function f1(e)
             println("g", e)
         end
         function g1(o)
             println("f", o)
         end
         oe(f1, g1) # don't need to scroll to see its 2 inputs
       end
goo
fee

```

---

<div class="post-metadata">

**Author:** ![mraic1](https://avatars.discourse-cdn.com/v4/letter/m/6bbea6/32.png) [@mraic1](https://discourse.julialang.org/u/mraic1)\
**Post date:** [October 5, 2025, 10:17am UTC](https://discourse.julialang.org/t/nested-do-blocks/132883/3 "2025-10-05T10:17:56Z")

</div>

Indeed, readability is most important here. I was just thinking, well, if we can shift one large initial argument to the tail, why not do it for two or maybe even more. However, the latter may indeed turn out confusing and separate functions would serve better in this case. Thank you for your prompt reply!
