Oh, sorry! I can't believe I missed @ngenerate.
This helped, thanks a lot!
Best,
Georgios

On Sunday, December 7, 2014 2:30:59 PM UTC+1, Tim Holy wrote:
>
> On Sunday, December 07, 2014 04:59:36 AM gexarcha wrote: 
> > Is it possible to modify nloops so that it takes a variable for the 
> number 
> > of loops? 
>
> No, because macros work at parsing time, and the value of a variable is 
> not 
> known at parsing time. 
>
> However, you have several options: 
>
> - Use @ngenerate 
>
> http://docs.julialang.org/en/latest/devdocs/cartesian/#supplying-the-number-of-expressions
>  
>
> - Directly generate your different function variants: 
> for N = 1:4 
>     @eval begin 
>         function myfunction{T}(A::Array{T,$N}) 
>             # body goes here 
>         end 
>     end 
> end 
>
> - Use julia 0.4 and use 
>     for I in eachindex(A) 
> (no macros required) 
>
> - Use julia 0.4 and use stagedfunctions (which work similarly to the @eval 
> version above). 
>
> --Tim 
>
>

Reply via email to