String concatenation

In G’MIC, v2.9.0, I’m trying to build up a string variable in a “for()” loop within an expression. I can do this at the command level, but not in an expression.

gmic_reference_290.pdf suggests the “string()” function, but I can’t get it to work. I simplify my command:

f:\web\im>%GMIC% eval "string ('zxc')"
[gmic]-0./ Start G'MIC interpreter.
[gmic]-0./ Evaluate expression 'string ('zxc')' and assign it to status.
[gmic]-0./ *** Error *** Command 'eval': Unrecognized function call 'string( 'zxc')'
 in expression 'string( 'zxc')'.

updata290.gmic contains a command that uses “string()”, and its usage seems consistent with mine. What happens when I run that command? It seems to be broken:

f:\web\im>%GMIC% toes.png percentile [0],12,16
[gmic]-0./ Start G'MIC interpreter.
[gmic]-0./ Input file 'toes.png' at position 0 (1 image 267x233x1x3).
[gmic]-1./ Apply percentile averaging filter to image [0], with mask [0], min percentile 12% and max percentile 16%.
[gmic] *** Error in ./percentile/ *** Command 'eval': Unrecognized function call
 'string('N[',p,']=j(',x - w2,',',y - h2,');')'
 in expression '...t = string('N[',p,']=j(',x - w2,',',y - h2,');')...'.

I’m a G’MIC newbie, so I expect I’m doing something wrong. So my questions are:

  1. How should I use “string()”?

  2. Is there a better way to concatenate strings?

EDIT: I should add, I’m on Windows 8.1.

Hello Alan,

string() seems indeed the function to use. Unfortunately, it has been introduced only in version 2.9.1 of G’MIC (which is still under development).
The percentile command does not work indeed, for users of version 2.9.0.

You may want to try the latest snapshot of 2.9.1_pre version of G’MIC. Depending on the OS or Unix flavor you use, it will be more or less easy to get :slight_smile:
We have some binaries available here : https://gmic.eu/files/prerelease/
But the best way to get it for testing, is to recompile it. If you are using Linux, it should not be so hard. For Windows, I suggest you take the pre-build binary from the G’MIC site.

G’MIC 2.9.1 is almost ready, so it shouldn’t be too long before the release.

And yes, string() is a very convenient function :slight_smile:
If you really need to make it work for 2.9.0, then a workaround is to allocate a large string, and use copy() to fill it, like this:

bug :
  eval "
str  = vector1024();
substr1  = 'hello ';
substr2 = 'folks !';
p = 0;
copy(str[p],substr1);
p+=size(substr1);
copy(str[p],substr2);
echo('str = ',str);"

But it’s not always easy to determine the length of each substring, and in that case,
length = find(substr,0)%size(substr) maybe useful too.
But it’s a lot more complicated than using string() (which is the reason why it has been introduced).

Many thanks, David, for the explanation and workarounds.

I avoid development versions when I’m learning a product, in the hope that when I hit a problem it’s probably my understanding.

I’ve loads of other stuff to do, so I’ll stick with 2.9.0 for now, and come back to concatenation when 2.9.1 is released.