# Metaprogramming: substitute the name of the argument

**URL:** <https://discourse.julialang.org/t/metaprogramming-substitute-the-name-of-the-argument/116867>\
**Category:** New to Julia\
**Tags:** macros, metaprogramming\
**Created:** [July 10, 2024, 11:31am UTC](https://discourse.julialang.org/t/metaprogramming-substitute-the-name-of-the-argument/116867 "2024-07-10T11:31:11Z")\
**Posts on this page:** 1\
**Showing post:** 5

<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 10, 2024, 2:01pm UTC](https://discourse.julialang.org/t/metaprogramming-substitute-the-name-of-the-argument/116867/5 "2024-07-10T14:01:59Z")

</div>

> [@dmi3kno](#):
>
> Writing macros is probably inevitable here, but I tried to see it I could stay within the familiar territory of combining functions. I seem to find some traces of function manipulation [here](http://fluxml.ai/MacroTools.jl/stable/utilities/).
> 
> The use-case is that I want to have a collection of function factories that manipulate function calls to produce more complex functions from simpler functions

You [don’t generally need metaprogramming](https://discourse.julialang.org/t/how-to-warn-new-users-away-from-metaprogramming/35022) for this. Just use higher-order functions.

> [@dmi3kno](#):
>
> I am writing a function factory that takes two functions and weighs them by some `_wt` \in (0,1).

For example, this seems to match the pattern you want?

```julia
fun_mix(fun1, fun2) = (u; wt=0.5, kws...) -> wt * fun1(u; kws...) + (1-wt) * fun2(u; kws...)

```

giving e.g.

```julia
julia> fmix = fun_mix(sin, cos)
#19 (generic function with 1 method)

julia> fmix(0.3)
0.6254283478934728

julia> fmix(0.3; wt=0.9)
0.3615018349077662

```

---

_[View the full topic](https://discourse.julialang.org/t/metaprogramming-substitute-the-name-of-the-argument/116867)._
