Re: [julia-users] "pass" a function to a module

2014-03-28 Thread andreas
Thanks again for the inputs! It let me to the following solution: ## --- module mymodule function make_foo(f::Function) !method_exists(f, (Real,)) ? error("provide function with 'Real' argument.") : nothing ## create new methods foo(x::Real) = f(x::Real) function foo(x

Re: [julia-users] "pass" a function to a module

2014-03-27 Thread Ivar Nesje
The module might also export a macro that you can apply to the method declaration.

Re: [julia-users] "pass" a function to a module

2014-03-27 Thread Stefan Karpinski
I think that design is flawed – you don't want to be adding random methods to user-supplied functions. You could just use a helper function in the definition of bar that applies the foo transformation using a user-supplied anonymous function applied to each scalar. On Thu, Mar 27, 2014 at 10:26 A

Re: [julia-users] "pass" a function to a module

2014-03-27 Thread andreas
Thanks for the fast response! However, when I change bar as proposed in the module this gives an error "No method foo(Array)": foo(x::Real) = x^2 bar(foo, [1:3]) As far I understand passing foo as function argument to bar(f, y) is not sufficient. The problem is that bar() uses foo(x::Real) a

Re: [julia-users] "pass" a function to a module

2014-03-27 Thread andreas
Thanks for the fast response! However, when I change bar in the module this gives an error "No method foo(Array)": foo(x::Real) = x^2 println(bar(foo, [1:3])) As far I understand passing foo as function argument to bar(f, y) is not sufficient. The problem is that bar() uses

Re: [julia-users] "pass" a function to a module

2014-03-27 Thread Stefan Karpinski
Aka function arguments – I've been doing too much wrapping of C libraries lately. Example: function bar(f,y) a = length(y) [f(a) f(y)] end Which can be used like this: bar(y) do x # body of f(x) end You can also pass an explicit function argument as bar(f,y). (I swear this email wa

Re: [julia-users] "pass" a function to a module

2014-03-27 Thread Stefan Karpinski
Callbacks? On Thu, Mar 27, 2014 at 8:04 AM, andreas wrote: > > Dear list, > > I'd like to be able to "pass" a function to a module, lets say > foo(x::Real). foo(x::Real) is used in the module and more methods are > added (which make use of foo(x::Real)). > > My idea is that the user loads the

[julia-users] "pass" a function to a module

2014-03-27 Thread andreas
Dear list, I'd like to be able to "pass" a function to a module, lets say foo(x::Real). foo(x::Real) is used in the module and more methods are added (which make use of foo(x::Real)). My idea is that the user loads the module and can then define foo(x::Real). If the user later redefines this