[Gambas-user] Wrong error message

Benoît Minisini gambas at ...1...
Tue May 4 19:57:14 CEST 2010


> 
> The problem is not very clear to me, but the following should be right:
> gambas uses operators to cast its operands; if it was not so, then why
> use "&" instead "+" to concatenate strings? But, when you use notations
> like "+=", you have a variable on the left (an L-Value), not a value you
> can cast... now, if the user writes something that can not work, like:
> 
>     sString$ /= 3
> 
> the compiler should detect this. As Jussi says, this is a minor issue,
> because even if the compiler does not notice, the interpreter will - as
> soon the user checks the program. But this kind of check would be
> responsibility of the compiler, not the interpreter.

The "?=" operators are just syntactic sugar. "A ?= B" is replaced by "A = A ? 
B" at compilation time. So the effect of reading values (as you said) depends 
on how the "?" operator works. And the effect of writing the value back always 
use automatic conversion

> 
> About the "why not converting while writing"... it could be a good idea,
> but "sString$ /= 3" what should do? Probably take the integer value
> stored in sString$, divide by three, convert again in string, and store
> the result back in sString$... 

'sString$ /= 3' is equivalent to 'sString$ = sString$ / 3'. So sString$ is put 
on the stack, and the "/" automatically converts that string to a number (if 
it can). Then, once the division is done, the resulting floating point number 
is assigned to sString$, and so automatically converted to a string first.

Regards,

-- 
Benoît Minisini




More information about the User mailing list