Pregunta

I am not sure if it is possible, but I would like to be able to grab the default argument values of a function and test them and the code within my functions without having to remove the commas (this is especially useful in the case when there are many arguments).

In effect, I want to be able to have commas when sending arguments into the function but not have those commas if I copy and paste the arguments and run them by themselves.

For example:

function foo(
    x=1,
    y=2,
    z=3
  ) 

  bar(x,y,z)
end

Now to test pieces of the function outside of the code block, copy and paste

x=1,
y=2,
z=3

bar(x,y,z)

But this gives an error because there is a comma after x=1

Perhaps I am not asking the right question. If this is strange, what is the preferred method for debugging functions?

¿Fue útil?

Solución

It isn't pretty but if you define your function like:

function foo(
    (x=1),
    (y=2),
    (z=3)
  ) 

  bar(x,y,z)
end

then it works as you describe.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top