# Any tools for making expressions composed functions from nested function calls?

**URL:** <https://discourse.julialang.org/t/any-tools-for-making-expressions-composed-functions-from-nested-function-calls/73446>\
**Category:** Data\
**Tags:** metaprogramming\
**Created:** [December 21, 2021, 5:30pm UTC](https://discourse.julialang.org/t/any-tools-for-making-expressions-composed-functions-from-nested-function-calls/73446 "2021-12-21T17:30:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [December 21, 2021, 5:30pm UTC](https://discourse.julialang.org/t/any-tools-for-making-expressions-composed-functions-from-nested-function-calls/73446/1 "2021-12-21T17:30:30Z")

</div>

In a macro, I’m trying to turn the expression `f(g(x))` into `(f ∘ g)(x)`.

To make sure I’m not trying to re-invent the wheel, I figured I would ask here if anyone has written a macro which does this.

---

<div class="post-metadata">

**Author:** ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Post date:** [December 21, 2021, 9:26pm UTC](https://discourse.julialang.org/t/any-tools-for-making-expressions-composed-functions-from-nested-function-calls/73446/2 "2021-12-21T21:26:24Z")

</div>

The tricky case is probably something like:

```julia
(x -> x)((x -> x)(x))

```

into

```julia
((x -> x) ∘ (x -> x))(x)

```

(of course likely with a more complex body.)

But if you want to restrict yourself to cases where `f` and `g` are `Symbol`s this should be a one-liner in a macro I think.

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [December 21, 2021, 9:36pm UTC](https://discourse.julialang.org/t/any-tools-for-making-expressions-composed-functions-from-nested-function-calls/73446/3 "2021-12-21T21:36:45Z")

</div>

Yeah. I think we can restrict ourselves to scenarios where `f` and `g` are symbols. It should be easy.
