another day, another unexplainable gen compilation error

Diemo Schwarz's icon

another gen conundrum: below code gives

jit_gen: Gen patcher not compiled

but no indication what the problem is. What's more, the code compiles either by commenting the line

theta = warmness(hue, sat, val);

or by uncommenting the block in /* ... */ (which does the same calculation as the warmness function).
This hints at a translation problem in gen.
Any insights are welcome.
Best

warmness (h, s, v)
{
    T = 0;
    w = s * v; //weighted
    h = h*360; //hue on a 360° circle
    if (h > 75 && h < 285) //binary assignement
    {
        T = -1;
    }
    else
    {
        T = 1;
    }

    thet = T * w;
    return thet;
}

index = swiz(cell, 0); // histogram bin index
hue = floor(index / 64);
sat = floor((index - hue * 64) / 8);
val = index - hue * 64 - sat * 8;

// this line makes gen not compile...
theta = warmness(hue, sat, val);

/*...but only when this block is commented....
// if uncommented, it compiles!
    T = 0;
    w = sat * val / 64; //weighted with s * v in [0..1]
    hue = hue / 32 * 360; //hue on a 360° circle
    if (hue > 75 && hue < 285) //binary assignement
    {
        T = -1;
    }
    else
    {
        T = 1;
    }

    theta = T * w;
*/
out1 = theta;

Max Patch
Copy patch and select New From Clipboard in Max.

Rob Ramirez's icon

maybe theta is a reserved word in gen ?

👽'tW∆s ∆lienz👽's icon

maybe theta is a reserved word in gen ?

ha, i've broken gen many times using reserved words(kept naming my params 'mix' whenever it controlled the mix of the 'mix' object, 😅 ...for some reason, it would work sometimes, and then as the patch grew more complex, not)

Diemo Schwarz's icon

it is definitely not a reserved word problem (same error with a different name).
However, further testing reveals a hint that it is a problem with the function after all:
Simply having a line assigning to theta will make the code compile, e.g.

thetaxxx = warmness(hue, sat, val);
thetaxxx = 0;
out1 = thetaxxx;

presumably this is because the translator figures out that the function's return value is not used and the call can be elided.
So, gen has a problem with the function mechanism itself, because the same code inline works fine.

Diemo Schwarz's icon

After more trials and simplifications, I could pinpoint gen's translation error:

func3 (h, s, v)
{
h = 1; // assigning to a function param is an undocumented and undetected gen error
return s * h;
}
res = func3(1, 2, 3); // only when the function is called, does gen report that it can't compile
out1 = res;

The question for us all is: Why should we put up with this? Why should we lose an hour of creative work, figuring out by ourselves some limitation of the gen language that shouldn't be there in the first place, but that should at least be documented somewhere, and that MUST be detected and reported as an error by the translator.

👽'tW∆s ∆lienz👽's icon

The question for us all is: Why should we put up with this?

my humble condolences for your trouble here, and utmost gratitude for finding this... and i pretty much agree with your sentiment(there's alot to be desired in the way the entire Max environ is being documented these days: you have to go on Discord(and there too, you'll have better luck if you go at certain times), you have to learn how to get around the search on this site(by not using it at all), you have to find this or that YouTube channel for some esoteric information(and if you're looking for something specific, it can be difficult to use someone's channel page to search there), and to be honest with you: i don't exactly put up with it - for example, i've gotten so used to struggling on my own with Max, that i never file bug-reports anymore - if they want us to struggle so hard to learn their environ, they should struggle harder and harder to keep it afloat on their own... we shouldn't do any extra work unless they pay us at this point).
this is a problem with many of the 'tech communities' these days: without proper documentation, it becomes elitist, because the 'cool people' who are connected with the devs or the ones who create the newer functionalities, will get this information first, while the rest of us have to yell on forums because we don't even know what we're missing yet(and this might be more acceptable in a fully open-source context, but not at all when we pay for a product).

[Edit: also, Rob Ramirez has probably been the most helpful and sharing of all at Cycling74, they should give him a serious raise and model the rest of their participation and care after him <3]

Diemo Schwarz's icon

One thing that could make gen less unexpected and more efficient would be to allow to declare and call C functions in a codebox. Then one could do proper integer arithmetic, too.

And thanks for your compassion, Raja, it warms my heart. I agree, Rob and Joshua have been stellar in helping to figure out all these little and big undocumented quirks in gen. It would be easier on them, too, to finalise genexpr with a properly defined, documented, and validated syntax and semantics.