Hello everyone,

I am trying to create a function where they keyword arguments (essentially) 
depend on some other initial argument.  I was able to cobble some code 
together that works, but I'm not sure if there is a better way.  
Additionally, I have no idea what the second line is doing.  The basic idea 
of this code is that if method == "a", then I need to use use the argument 
with keyword "two".  Alternatively, if method == "b", then I need to use 
the argument with keyword "three".

My two questions are:
1.  What is the second line of the function actually doing?
2.  Is there a better way of doing this?

Self-contained code is below.  

Thanks, Joshua.

function f(method; k...)
    k = { i[1] => i[2] for i in k }
    if(method == "a")
        print(k[:two])
    elseif(method == "b")
        print(k[:three])
    end
end

f("a", two = reshape(1:10, 5, 2), three = reshape(1:8, 4, 2))
f("b", two = reshape(1:10, 5, 2), three = reshape(1:8, 4, 2))

Reply via email to