GreycLab / gmic

GREYC's Magic for Image Computing: A Full-Featured Open-Source Framework for Image Processing
Other
74 stars 12 forks source link

New math parser function idea: check() #70

Open Reptorian1125 opened 1 week ago

Reptorian1125 commented 1 week ago

I tried doing everything in one go with check instead of check + eval combo, but apparently, it does not support const. So, I decided to suggest a idea of check() which acts like math parser version of check command. Here's a real-world application:

failed=1;
eval "
    # snipped code
    condition?(
        set('failed',0;);
        # snipped code
    );"

if $failed error inv_inp fi

This also could be in the form of check and then eval without needing set(). So, you have to have two sections for one thing.

With check(), it looks simpler:

eval "
    # snipped code
    check(condition);
    # snipped code

check() returns 1, or throws a error when it doesn't meet criteria. Personally, I would do this.

The main reason for doing this is not having to copy code, which in one of my case is copying a ${2--1} twice.

dtschump commented 1 week ago

Why not:

   !condition?run('error \"Command $0: Error : condition does not hold\"');

?

Reptorian1125 commented 1 week ago

I mean, that can be done, but, it would not reveal the underlying formula used ala how print() works, and error message can definitely be expanded with more languages in mind (Yes, I know G'MIC is mostly english-only for now). And finally, check() seems to be much shorter form without ever having to write error message. So, I see a case for something like check(), but I understand that solution works too.