Re: [julia-users] Define functions in loop

2015-09-03 Thread Mauro
> Ok, makes sense. For what it’s worth (I’m very new at Julia, but have > been using Lisp/Scheme/Clojure for a while now)… In Lisp/Clojure I > think there’s a preference even for internal function definitions to > use macros vs eval for the reason that macros modify the source at > parse time, but

Re: [julia-users] Define functions in loop

2015-09-03 Thread Joshua Ballanco
Ok, makes sense. For what it’s worth (I’m very new at Julia, but have been using Lisp/Scheme/Clojure for a while now)… In Lisp/Clojure I think there’s a preference even for internal function definitions to use macros vs eval for the reason that macros modify the source at parse time, but eval wi

Re: [julia-users] Define functions in loop

2015-09-03 Thread Patrick Kofod Mogensen
Makes sense. So if you want to generate a lot of code in your package (similar functions or types for example), then you might loop over @eval's, but if you want your user to also add the same kind of functions, then you might prefer to make a macro and export that. On Thursday, September 3, 2

Re: [julia-users] Define functions in loop

2015-09-03 Thread Mauro
> Out of curiosity, why use `@eval` directly instead of defining a > macro? (I’m just trying to get a better feel for what’s more Julian.) Generally: Use eval when you want to generate code at a particular location. Conversely, macros are used if you want to provide a way for your users to generat

Re: [julia-users] Define functions in loop

2015-09-03 Thread Patrick Kofod Mogensen
To be honest, I also thought the macro-style was preferred, if what you're doing is actually metaprogramming (like the @endpoint in the blog post). Here, I think a makefun-function as opposed to @makefun doesn't quite communicate the nature of makefun. Although, all of this can just be personal

Re: [julia-users] Define functions in loop

2015-09-02 Thread Joshua Ballanco
Out of curiosity, why use `@eval` directly instead of defining a macro? (I’m just trying to get a better feel for what’s more Julian.) On September 2, 2015 at 12:44:39, Patrick Kofod Mogensen (patrick.mogen...@gmail.com) wrote: I'm in a train right now, but yes. Look up metaprogramming in the

[julia-users] Define functions in loop

2015-09-02 Thread Patrick Kofod Mogensen
I'm in a train right now, but yes. Look up metaprogramming in the docs, or look at the blog entry on refactoring code in Twitter.jl http://randyzwitch.com/julia-metaprogramming-refactoring

[julia-users] Define functions in loop

2015-09-02 Thread Robert DJ
Hi, I have a situation where a number of functions differ so little that it would make sense to define them by a loop. I don't know if I am using the correct jargon, but here is a small example to illustrate: type test A::Int B::Int end function A(T::test) T.A end fun