# Map over expressions?

**URL:** <https://discourse.julialang.org/t/map-over-expressions/1657>\
**Category:** Internals & Design\
**Created:** [January 23, 2017, 8:38pm UTC](https://discourse.julialang.org/t/map-over-expressions/1657 "2017-01-23T20:38:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bramtayl](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bramtayl/32/3614_2.png) [@bramtayl](https://discourse.julialang.org/u/bramtayl)\
**Post date:** [January 23, 2017, 8:38pm UTC](https://discourse.julialang.org/t/map-over-expressions/1657/1 "2017-01-23T20:38:13Z")

</div>

It might be slightly useful to define

```julia
map(f, e::Expr) = Expr(e.head, map(f, e.args)... )

```

It would be useful for recursive AST functions. Of course, users defining `map_expression` themselves would probably be fine too, but it’s something I find myself doing repeatedly.

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [January 23, 2017, 9:59pm UTC](https://discourse.julialang.org/t/map-over-expressions/1657/2 "2017-01-23T21:59:48Z")

</div>

Just out of curiosity, would `map!(f, e.args)` not be useful?

---

<div class="post-metadata">

**Author:** ![bramtayl](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bramtayl/32/3614_2.png) [@bramtayl](https://discourse.julialang.org/u/bramtayl)\
**Post date:** [January 23, 2017, 10:36pm UTC](https://discourse.julialang.org/t/map-over-expressions/1657/3 "2017-01-23T22:36:10Z")

</div>

Definitely in some situations. I tend to avoid mutating in place if at all possible when I program.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [January 24, 2017, 6:32am UTC](https://discourse.julialang.org/t/map-over-expressions/1657/4 "2017-01-24T06:32:33Z")

</div>

While I agree that it would be useful, I would not make it a method of `Base.map`. I don’t think that `map` should be defined for composite types, let alone in ways that transform only some of the fields.

That said, I think this would be a useful addition to some macro toolkit packages, maybe one of them will include it. Perhaps submit it as a PR to one of them?
