Apologies for the double (now triple) posting. Passing the function as an
argument as well, that becomes:
function f1(f, args...)
@show args
new_args = [modify(arg) for arg in args]
f(new_args...)
end
function f2(a, b)
@show a, b
end
f1(f2, 2, 3.5)
El sábado, 16 de mayo de 2015, 18:36:42 (UTC-5), David P. Sanders escribió:
>
>
>
> El sábado, 16 de mayo de 2015, 18:26:48 (UTC-5), Eka Palamadai escribió:
>>
>> I am trying to write a function f1 that takes a function f2 and arguments
>> of f2 as parameters,
>> modifies some arguments of f2, and calls f2 with the modified arguments.
>>
>> function f1(f2::Function, args...)
>> #iterate through the args and modify some of the contents of args
>> f2(args)
>> end
>>
>
> Depending on what you mean by "modifying", you don't need metaprogramming
> for this.
> For example:
>
>
> modify(x::Int) = 2x
> modify(x::Float64) = 3x
>
> function f1(args...)
> new_args = [modify(arg) for arg in args]
> f2(new_args...)
> end
>
> function f2(a, b)
> @show a, b
> end
>
> f1(2, 3.5)
>
>
> This gives
>
> (4,10.5)
>
>
> David.
>
>
>
>
>
>>
>> Any suggestions on how to do this?
>>
>> Thanks.
>>
>>
>>
>>
>>
>>
>>
>