# How one can evaluate @printf to be returned to a value

**URL:** <https://discourse.julialang.org/t/how-one-can-evaluate-printf-to-be-returned-to-a-value/117669>\
**Category:** General Usage\
**Tags:** metaprogramming\
**Created:** [July 31, 2024, 10:03am UTC](https://discourse.julialang.org/t/how-one-can-evaluate-printf-to-be-returned-to-a-value/117669 "2024-07-31T10:03:49Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [July 31, 2024, 11:41am UTC](https://discourse.julialang.org/t/how-one-can-evaluate-printf-to-be-returned-to-a-value/117669/6 "2024-07-31T11:41:00Z")

</div>

> [@khaledharizb](#):
>
> ```julia
> if (F==0)
> myfunc = "IA"
> elseif (F==1)
> myfunc = "IIA"
> end
> 
> ```

Instead of passing around functions as strings (or encoded as numbers like `F`), it is much better to simply pass them around as functions. e.g. if you set

```julia
myfunc = DeltaAII

```

you can just call `myfunc(1)`. A function called `DeltaAII` can also be passed as an argument to another function. This is called a [higher-order function](https://en.wikipedia.org/wiki/Higher-order_function).

PS. The literal answer to your original question is

```julia
func(x) = eval(Meta.parse(@sprintf("Delta%s(%f)",myfunc,x)))

```

but this is a classic anti-pattern. See [How to warn new users away from metaprogramming](https://discourse.julialang.org/t/how-to-warn-new-users-away-from-metaprogramming/35022) … in particular, you almost never want to pass functions or expressions as strings that you parse and evaluate. It’s fragile, slow, and inflexible. Julia has [first-class functions](https://en.wikipedia.org/wiki/First-class_function) — enjoy it!

---

_[View the full topic](https://discourse.julialang.org/t/how-one-can-evaluate-printf-to-be-returned-to-a-value/117669)._
