# Using @sprintf inside a macro

**URL:** <https://discourse.julialang.org/t/using-sprintf-inside-a-macro/45275>\
**Category:** General Usage\
**Tags:** macros\
**Created:** [August 20, 2020, 4:37pm UTC](https://discourse.julialang.org/t/using-sprintf-inside-a-macro/45275 "2020-08-20T16:37:02Z")\
**Posts on this page:** 1\
**Showing post:** 17

<div class="post-metadata">

**Author:** ![simeonschaub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simeonschaub/32/216566_2.png) [@simeonschaub](https://discourse.julialang.org/u/simeonschaub)\
**Post date:** [August 22, 2020, 5:38pm UTC](https://discourse.julialang.org/t/using-sprintf-inside-a-macro/45275/17 "2020-08-22T17:38:25Z")

</div>

Splatting doesn’t quite work like this in macro calls. Try:

```julia
macro myprintf(x, y...)
    :(print(now(), ":", @sprintf($x, $(esc.(y)...))))
end

```

instead. You need to do the splatting inside the interpolation, for `y` to be spliced correctly into the expression.

~~Edit: I don’t think you even need the `esc`.~~

---

_[View the full topic](https://discourse.julialang.org/t/using-sprintf-inside-a-macro/45275)._
