That is,
julia f(x::Int, y::Int=5, z::Int=3) = x+y+z
f (generic function with 3 methods)
julia f(x::Float64, args...) = f(floor(Int,x), args...)
f (generic function with 4 methods)
julia f(5.0,1,2)
8
julia f(5.0)
13
On Tuesday, July 21, 2015 at 7:53:01 AM UTC-7, Seth wrote:
On Tuesday, July 21, 2015 at 7:14:02 AM UTC-7, Linus Härenstam-Nielsen
wrote:
I am looking for a way to automatically pass on all keyword arguments
through a function. Naively I would like to be able to do something like
this:
f(x::Int; y::Int=5, z::Int=3) = x+y+z
f(x::Float64; args...) = f(floor(x), args...)
But that doesn't work currently (actually, it causes StackOverflowError
in 0.4.0). So far I've been using the following instead:
f(x::Float64, y::Int=5, z::Int=3) = f(floor(x), y=y, z=z)
But that gets messy very quickly if there are several keyword arguments
to handle. Does anyone know of a clean way to do this?
I think you're getting the stack overflow because your call to floor
doesn't convert to Int, so f(x::Float64; args...) keeps getting called
recursively. What happens if you change your second method to
f(x::Float64, y::Int=5, z::Int=3) = f(floor(Int, x), y=y, z=z)
instead?