Hello, I know that it is allowed to use keyword arguments to define later arguments like, e. g., this:
f(;a=1, b="$a") = b
Now calling
f()
f(;a=2)
works fine. However I cannot write this one:
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).
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.
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.
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.