PB5.00b7 no longer allows testing Not with string?

Just starting out? Need help? Post your questions and find answers here.
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

PB5.00b7 no longer allows testing Not with string?

Post by Kukulkan »

With the most recent V5.00Beta7 I can no longer test strings using Not?

Code: Select all

If Not Test.s
  ; do something
EndIf
Throws error Line 1: 'Not' operand can not get using with strings.

Why? My code compiled fine with the previous versions up to beta 4. Now it throws errors every here and then...

And the sentence is wrong spelled I think. Better is "...can not get used with..."

Kukulkan
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: PB5.00b7 no longer allows testing Not with string?

Post by Fred »

That's it. It barely worked only for simple cases (if you were lucky), and the doc explicitely forbid this use, so now the compiler enforce this rule to avoid strange behaviours.

It can be replaced by:

Code: Select all

If String$ = ""
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: PB5.00b7 no longer allows testing Not with string?

Post by STARGÅTE »

Same for:

Code: Select all

If A$ XOr B$

EndIf
now:

Code: Select all

If A$<>"" XOr B$<>""

EndIf
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Re: PB5.00b7 no longer allows testing Not with string?

Post by Kukulkan »

Ok, I'll have to change code now...

If this was a source for errors in the past, I agree with this. Seems better style.

Kukulkan
BorisTheOld
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Apr 24, 2012 5:08 pm
Location: Ontario, Canada

Re: PB5.00b7 no longer allows testing Not with string?

Post by BorisTheOld »

Kukulkan wrote: Throws error Line 1: 'Not' operand can not get using with strings.

And the sentence is wrong spelled I think. Better is "...can not get used with..."
More correctly, the message should read: 'Not' operand cannot be used with strings.
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: PB5.00b7 no longer allows testing Not with string?

Post by Psychophanta »

IMO, for conditional expressions, the 'Not' is a nonsense, because only 'Or', 'And' and 'XOr' are necessary.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
Crusiatus Black
Enthusiast
Enthusiast
Posts: 389
Joined: Mon May 12, 2008 1:25 pm
Location: The Netherlands
Contact:

Re: PB5.00b7 no longer allows testing Not with string?

Post by Crusiatus Black »

Psychophanta wrote:IMO, for conditional expressions, the 'Not' is a nonsense, because only 'Or', 'And' and 'XOr' are necessary.
Why is 'Not' a nonsense?

Code: Select all

If (Not (a And getSomething(b) > 20 And isSomething(a)))
Is 'Not' not convenient in these situations?
Image
Bas Groothedde,
Imagine Programming

I live in a philosophical paradoxal randome filled with enigma's!
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: PB5.00b7 no longer allows testing Not with string?

Post by Psychophanta »

I meant it is a surplus word since it can be done in other way in all cases. Even i realize it could be a little bit less readable sometimes.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Niffo
Enthusiast
Enthusiast
Posts: 504
Joined: Tue Jan 31, 2006 9:43 am
Location: France

Re: PB5.00b7 no longer allows testing Not with string?

Post by Niffo »

Fred wrote:That's it. It barely worked only for simple cases (if you were lucky), and the doc explicitely forbid this use, so now the compiler enforce this rule to avoid strange behaviours.
:cry: I will have to rewrite tons of test statements in my projects. It also looks like a regression because near all other programming languages accepts this syntax.
Niffo
BorisTheOld
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Apr 24, 2012 5:08 pm
Location: Ontario, Canada

Re: PB5.00b7 no longer allows testing Not with string?

Post by BorisTheOld »

Niffo wrote:It also looks like a regression because near all other programming languages accepts this syntax.
The thing to remember about "IF" statements, in any language, is that they test the value of an integer expression. That's why NOT, XOR, AND, etc, can be used. However, a string is not a valid integer expression and must always be compared to something in order to create an integer value that represents True or False.

For example, the following are valid:

If String1 = String2
If Not (String1 = String2)

But the following are invalid:

If String1
If Not String1
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: PB5.00b7 no longer allows testing Not with string?

Post by PMV »

One of PB features is, that "If String" is valid. :wink:
BorisTheOld
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Apr 24, 2012 5:08 pm
Location: Ontario, Canada

Re: PB5.00b7 no longer allows testing Not with string?

Post by BorisTheOld »

I was talking about how the "If" statement works in real languages. :lol:

And yes, PB does allow "If string". Currently, a null string returns false and a non-null string returns true.

Therefore, using "If Not string" would seem to be a valid statement, it's just that it wasn't implemented correctly. However Fred says not, and suggests that we use the more normal forms such as, "If string1 = string2", etc, which is the way other languages work.

I would therefore argue that the "If string" usage should also be disallowed.
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: PB5.00b7 no longer allows testing Not with string?

Post by jassing »

BorisTheOld wrote:I would therefore argue that the "If string" usage should also be disallowed.
I agree with that -- I had to change a lot of code that I used "if not cValue" for "is cvalue empty" (or "") - if the 'not' variation is invalid, then "if stringvar" should also be invalid.


Moreover, if "If Not cValue" didn't work as you expected it to; we can not count on "If cValue" to work as we expect it to -- correct?

I mean

if not .f. is invalid, how can if .t. be valid?
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: PB5.00b7 no longer allows testing Not with string?

Post by PMV »

Its always the same ... just because something that was never
allowed to be was just used because it seemed to work fine.
Now it is disallowed and some people are going crazy. The
only think i can see here is, that it should be blocked from
the beginning to avoid this. :lol:


Maybe you have luck and Fred will tell you why it is like it is
... good luck. :)

MFG PMV
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: PB5.00b7 no longer allows testing Not with string?

Post by luis »

BorisTheOld wrote:
Kukulkan wrote: Throws error Line 1: 'Not' operand can not get using with strings.

And the sentence is wrong spelled I think. Better is "...can not get used with..."
More correctly, the message should read: 'Not' operand cannot be used with strings.
Actually should be "operator" :wink:
"Have you tried turning it off and on again ?"
A little PureBasic review
Post Reply