Benoît Minisini ha scritto:
>> Rolf-Werner Eilert wrote:
>>     
>>> Just stumbled over this when trying to implement a small copying
>>> function:
>>>
>>>    FOR EACH datei IN Dir(opfad, odatei & ".*")
>>>      IF NOT file.Ext(opfad &/ datei) = "lock" THEN
>>>        COPY opfad &/ datei TO ziel &/ datei
>>>        SELECT CASE file.Ext(ziel &/ datei)
>>>        CASE "fehl", "feldbak", "felder", "notizen"
>>>          SHELL "chgrp kartei " & ziel &/ datei WAIT
>>>          SHELL "chmod 660 " & ziel &/ datei WAIT
>>>        CASE "konto", "kontobak", "ktx", "ktxbak"
>>>          SHELL "chgrp konto " & ziel &/ datei WAIT
>>>          SHELL "chmod 660 " & ziel &/ datei WAIT
>>>        END SELECT
>>>      END IF
>>>    NEXT
>>>
>>> IF NOT ... = ... THEN
>>>
>>> wouldn't copy anything, although only one file has the given extension.
>>> When I change this line into
>>>
>>> IF file.Ext(opfad &/ datei) <> "lock" THEN
>>>
>>> everything runs as expected. Doesn't make sense to me as both ways
>>> should mean the same in my understanding of logical NOT (which doesn't
>>> mean too much... :-) )
>>>
>>> Regards
>>>
>>> Rolf
>>>       
>>  From the docs, NOT is an operator that makes a boolean it's opposite
>> (TRUE turns to FALSE and vice versa) and will also invert each bit in an
>> integer.  NOT(11) = -12 because that's what you get when you change
>> every bit from on to off and vice versa.
>>
>>  From other examples in the docs, if you NOT a string with something in
>> it, you will get FALSE.  However, if you NOT an empty string, you will
>> get TRUE.
>>
>>     
>
> In other words, try to use brackets: IF NOT (...) = ... THEN
>   
There is some wrong things in here, I think.

First, the operator NOT applied to a string is a little strange. It can 
be handy for testing whether the string is empty or not, but doing so 
it's ambiguous - it could be better to write:

    if astring <> "" then...

Anyway, the result of such operation (NOT astring) would be a boolean. 
Now, comparing a boolean value to a string should give a syntax error.

But go a step further. Your affirmation "try to use brackets" does not 
work, at least in principle, because he wants to test the contents of 
the first string against another string. By applying NOT only to the 
first argument, the contents of the first string is lost. The 
parenthesis should be put around the whole test: NOT (astring = "xxx") THEN.

I would prefer the NOT operator be incompatible with strings and, doing 
so, the expression

    NOT astring = "xxx"

could not be interpreted like "negate astring and go ahead" but instead 
as "compare astring, and then negate" (if the parser can take such 
decisions). Other languages, notably C, use different operators for 
different results (! vs ~, && vs &...). More evoluted languages can 
determine from the context the exact meaning of several operators. But 
the gambas current way is the more ambiguous of all...

Regards,
Doriano.

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user

Reply via email to