How to pass first argument of a function as default and only input second argument

function addremove( x=100, y=10)
x+y, x-y
end

I can put second argument as default value by
addremove(10)
and this will result (20, 0)

but how can I put first argument as default and input only second argument?

I remember some functions in other modules were defined in such a way and worked well.

Consider using keyword arguments.

Also, please quote your code.

1 Like

If you want to keep this positional then you can define addremove(x, y) without defaults and also define this:

addremove(y) = addremove(default_x, y)

All that default argument syntax does is define such methods for you.

1 Like

This is generally only used when the first argument(s) have a different type (eg rand).

While there is nothing wrong with it per se, it may be somewhat confusing and unexpected for arguments of the same type.

1 Like