Re: [julia-users] Passing keyword arguments through a function

2015-07-21 Thread Linus Härenstam-Nielsen
This worked! Didn't realize you could use ";" when calling functions. 


On Tuesday, July 21, 2015 at 4:49:36 PM UTC+2, Stefan Karpinski wrote:
>
> f(floor(x); args...) should work.
>
> On Tue, Jul 21, 2015 at 10:14 AM, Linus Härenstam-Nielsen <
> linu...@gmail.com > 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?
>>
>>
>>
>

Re: [julia-users] Passing keyword arguments through a function

2015-07-21 Thread Yichao Yu
On Tue, Jul 21, 2015 at 10:48 AM, Stefan Karpinski  wrote:
> f(floor(x); args...) should work.

Relevant documentation is here[1] in case you have other confusions
about keyword arguments.

[1] http://julia.readthedocs.org/en/latest/manual/functions/#keyword-arguments

>
> On Tue, Jul 21, 2015 at 10:14 AM, 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?
>>
>>
>


Re: [julia-users] Passing keyword arguments through a function

2015-07-21 Thread Stefan Karpinski
f(floor(x); args...) should work.

On Tue, Jul 21, 2015 at 10:14 AM, Linus Härenstam-Nielsen <
linush...@gmail.com> 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?
>
>
>