Extension of begin for gmic?

I would like to do beginx(); or beginy(); or beginz(); or beginc(); in gmic. The reason why I would like to see these is that one can make variables only once for x or y and thereby avoiding speed issues. Are these possible now?

f beginx(foo=x);foo*y

This is equilavent to:

 for(x=0,x<w,x++,
     foo=x;
     for(y=0,y<h,y++,
         foo*y;
     );
 );

Additional idea, I would like to do iv#channel or iv#perchannel inside fill.

I am not quite sure about begin() to begin with.

The second idea has been on my wish list since the beginning but something that I have kept to myself; e.g., you could do i0 but not iv0.

begin can be used to evaluate result of variable only once. So you don’t have to reassign variables per pixels. It sped my filter significantly. It can also be used to enable dynamic variables like the case of altern in Chaos formula found in rep_thorn_fractal. the result of altern in one pixel gets passed to the next pixel instead of starting over with assigned variable.

Could you give me a dead simple foo example of reassignment and its begin() version? Sorry about making this a Q&A but I am curious now. I hope to have a firmer grasp of the concept.

f "begin(a=5;b=cos(a);foo=(a+b));"

This is equal to #almost now that I checked again#

a=5;
b=cos(a);
foo=(a+b);
#for(x,y)loop_here#

a,b,foo are only evaluated once.

It seem like G’MIC assigns foo to all pixels, but however, it skips over begin() per pixel. altern=0 gets skipped over in the case of rep_tfrac.

There is no need for beginx(), beginy() or beginz().
Because, if you want to evaluate an expression only once per row, for instance:

eval. ">begin(foo = 0);
      !x?( foo+=1 ); # Do it only for each row
      0;  # Do nothing
      end( print(foo) );"
1 Like

It’s hard to express what I’m thinking in words, but I guess that after the end statement, whatever variable assigned in there is no longer being reassigned right? It’s a bit confusing, and @afre himself isn’t sure on begin().