# Use keyword in the upcomming keywords

**URL:** <https://discourse.julialang.org/t/use-keyword-in-the-upcomming-keywords/12497>\
**Category:** General Usage\
**Tags:** question\
**Created:** [July 19, 2018, 2:45pm UTC](https://discourse.julialang.org/t/use-keyword-in-the-upcomming-keywords/12497 "2018-07-19T14:45:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![stakaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stakaz/32/4740_2.png) [@stakaz](https://discourse.julialang.org/u/stakaz)\
**Post date:** [July 19, 2018, 2:45pm UTC](https://discourse.julialang.org/t/use-keyword-in-the-upcomming-keywords/12497/1 "2018-07-19T14:45:32Z")

</div>

Hello, I know that it is allowed to use keyword arguments to define later arguments like, e. g., this:

```julia
f(;a=1, b="$a") = b

```

Now calling

```julia
f()
f(;a=2)

```

works fine. However I cannot write this one:

```julia
f(;a=3, b="$a")

```

which complains that `a` is not defined.

Is it a design issue or a bug and is there a way to circumvent this.  
(Of cause I can define `a` before the call and than use it in the call but this results in additional variable which I actually do not need beside for this call).

---

<div class="post-metadata">

**Author:** ![korsbo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/korsbo/32/15942_2.png) [@korsbo](https://discourse.julialang.org/u/korsbo)\
**Post date:** [July 19, 2018, 3:01pm UTC](https://discourse.julialang.org/t/use-keyword-in-the-upcomming-keywords/12497/2 "2018-07-19T15:01:14Z")

</div>

You are in the second case creating the full string (evaluating the “$a”) before it is passed on to the function. If you do not have an `a` in your namespace, then this will error before the function call was ever made.

I would not guess that you can circumvent this. And I am not entirely sure why you would want to? `b` gets a value from `a` if you do not try to pass this.

---

<div class="post-metadata">

**Author:** ![stakaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stakaz/32/4740_2.png) [@stakaz](https://discourse.julialang.org/u/stakaz)\
**Post date:** [July 19, 2018, 3:10pm UTC](https://discourse.julialang.org/t/use-keyword-in-the-upcomming-keywords/12497/3 "2018-07-19T15:10:04Z")

</div>

The real case is kind of more complicated. Something like this:

```julia
f(;a=1, b=2, c=3, filename="default_$(a)_$(b)_$(c).dat") = ...

```

and call it later with

```julia
f(;a=4, b=5, c=6, filename="something_different_$(a)_$(b)_$(c).dat") 

```

It would have been really nice if that would be possible. But I agree, I don’t thing it is.

---

<div class="post-metadata">

**Author:** ![korsbo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/korsbo/32/15942_2.png) [@korsbo](https://discourse.julialang.org/u/korsbo)\
**Post date:** [July 19, 2018, 3:27pm UTC](https://discourse.julialang.org/t/use-keyword-in-the-upcomming-keywords/12497/4 "2018-07-19T15:27:35Z")

</div>

I see the problem. In your particular example, you could add another argument for the `name_prefix="default"`, but I do not know of a general solution to your actual question.

---

<div class="post-metadata">

**Author:** ![korsbo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/korsbo/32/15942_2.png) [@korsbo](https://discourse.julialang.org/u/korsbo)\
**Post date:** [July 19, 2018, 3:29pm UTC](https://discourse.julialang.org/t/use-keyword-in-the-upcomming-keywords/12497/5 "2018-07-19T15:29:32Z")

</div>

Also, you could do

```julia
a = 4
b = 5
c = 6
f(a=a, b=b, c=c, filename="something_different_$(a)_$(b)_$(c).dat")

```

But, again, I don’t know how to delay the string interpolation util the function has been called.

---

<div class="post-metadata">

**Author:** ![stakaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stakaz/32/4740_2.png) [@stakaz](https://discourse.julialang.org/u/stakaz)\
**Post date:** [July 19, 2018, 3:43pm UTC](https://discourse.julialang.org/t/use-keyword-in-the-upcomming-keywords/12497/6 "2018-07-19T15:43:57Z")

</div>

Yes, both ways are known to me 😉 Thanks. The first one restricts me to have a fixed structure of the string and the second is exactly this definition of dummy variables… But yeah, I do it in this way… Probably one could pass an `Expr` and then `@eval` it but this would result in a global variable.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [July 19, 2018, 3:47pm UTC](https://discourse.julialang.org/t/use-keyword-in-the-upcomming-keywords/12497/7 "2018-07-19T15:47:14Z")

</div>

Passing the `a` keyword does not create a local `a` variable in the caller. Even though it uses the `=` syntax or does something quite distinct.
