# Reference to the value of a named function argument

**URL:** <https://discourse.julialang.org/t/reference-to-the-value-of-a-named-function-argument/55572>\
**Category:** New to Julia\
**Created:** [February 18, 2021, 8:37pm UTC](https://discourse.julialang.org/t/reference-to-the-value-of-a-named-function-argument/55572 "2021-02-18T20:37:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![xor](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xor/32/21782_2.png) [@xor](https://discourse.julialang.org/u/xor)\
**Post date:** [February 18, 2021, 8:37pm UTC](https://discourse.julialang.org/t/reference-to-the-value-of-a-named-function-argument/55572/1 "2021-02-18T20:37:28Z")

</div>

Within a function body I’d like to refer to a value of a named argument.  
An example of what I have in mind, how to implement `f`:

```julia
function f(; arg1, arg2, argname)
    println("value of argument named $argname is: ???")
end

```

so that it’s invocation produces:

```julia
julia> f(arg1 = 1, arg2 = "b", argname = "arg1")

value of argument named arg1 is: 1

```

---

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [February 18, 2021, 8:49pm UTC](https://discourse.julialang.org/t/reference-to-the-value-of-a-named-function-argument/55572/2 "2021-02-18T20:49:25Z")

</div>

I am not sure I understood your question. `$argname` already prints _the value_ of argname.

So to print your sentence you can use just:

```julia
 println("value of arg1 is: $arg1")

```

---

<div class="post-metadata">

**Author:** ![xor](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xor/32/21782_2.png) [@xor](https://discourse.julialang.org/u/xor)\
**Post date:** [February 18, 2021, 9:26pm UTC](https://discourse.julialang.org/t/reference-to-the-value-of-a-named-function-argument/55572/3 "2021-02-18T21:26:17Z")

</div>

I am after the value of the argument named by `argname`.

In my example the output should be “b” if the value of `argname` is arg2

I amended the example to make this more clear.

---

<div class="post-metadata">

**Author:** ![greg\_plowman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/greg_plowman/32/8100_2.png) [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)\
**Post date:** [February 18, 2021, 9:42pm UTC](https://discourse.julialang.org/t/reference-to-the-value-of-a-named-function-argument/55572/4 "2021-02-18T21:42:54Z")

</div>

Not really sure what you want or why. I suspect there’s a better way of doing what you really want.  
But this might be what you asking about directly?

```julia
function f(; kwargs...)
    arg = Symbol(kwargs[:argname])
    println("value of argument named ", arg, " is ", kwargs[arg])
end

f(arg1 = 1, arg2 = "b", argname = "arg1")
f(arg1 = 1, arg2 = "b", argname = "arg2")

```
