Strange...

Just starting out? Need help? Post your questions and find answers here.
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Strange...

Post by Polo »

Don't know if it's supposed to be normal or not, but this code :

Code: Select all

3thing=0
Gives "Not a valid decimal number" :shock: Everytime I use a variable name starting with a number it says that ! How come I can't do that ??
benny
Enthusiast
Enthusiast
Posts: 465
Joined: Fri Apr 25, 2003 7:44 pm
Location: end of www
Contact:

Post by benny »

@Polo:

I guess it's just the definition of the purebasic parser. In the help it says that
variables shouldn't start with a number.

So, when the parser parses a new word which starts with a numeric value it
assumes that it is a decimal number and not a variable.

That's all ...
regards,
benny!
-
pe0ple ar3 str4nge!!!
Chris
User
User
Posts: 60
Joined: Wed Jun 11, 2003 4:54 pm
Location: Somewhere... But i can see you!

Post by Chris »

A variable can't begin by a number.
My english is bad !!!... It's normal, i'm french :lol:
My english is not really the English.
It's the FrogLish (Froggy's English) ;)
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

All right, I still find this weird, anyway...
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Chris wrote:A variable can't begin by a number.
So then it should give the error "not a valid variable" and not "not a valid decimal number", shouldn't it?
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

Trond wrote:
Chris wrote:A variable can't begin by a number.
So then it should give the error "not a valid variable" and not "not a valid decimal number", shouldn't it?
But then, if the compiler could catch the error, it could also make the variable working, so that's why I posted it here, I think it's possible :)
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Polo wrote:
Trond wrote:
Chris wrote:A variable can't begin by a number.
So then it should give the error "not a valid variable" and not "not a valid decimal number", shouldn't it?
But then, if the compiler could catch the error, it could also make the variable working, so that's why I posted it here, I think it's possible :)
Whether variables can start with a number or not is not a question of possible/not possible, it's a question of language design.
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post by Pupil »

Trond wrote:
Chris wrote:A variable can't begin by a number.
So then it should give the error "not a valid variable" and not "not a valid decimal number", shouldn't it?
The error is correct as it is, because "3thing" is not a valid decimal number, or do you dissagree? ;)
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Pupil wrote:
Trond wrote:
Chris wrote:A variable can't begin by a number.
So then it should give the error "not a valid variable" and not "not a valid decimal number", shouldn't it?
The error is correct as it is, because "3thing" is not a valid decimal number, or do you dissagree? ;)
The error message doesn't say _what_ isn't a valid decimal number.
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

3thing=128
128 is a "valid decimal number"
so "3thing" is the "not valid decimal number", but here it's a variable, so something's wrong somewhere.
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post by Pupil »

Trond wrote:The error message doesn't say _what_ isn't a valid decimal number.
Well, it's fairly obvious, isn't it? :)

However i agree that it would help if the compiler was a tad more explicit. An error message like the one below would've been more helpfull in pinpointing the problem:
"'3thing' is not a vaild decimal number."
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Pupil wrote:
Trond wrote:The error message doesn't say _what_ isn't a valid decimal number.
Well, it's fairly obvious, isn't it? :)
Try to type in 3thing on a line by itself. :wink: Also, "=" isn't a valid decimal number.

The thing is: It reports that it got something which wasn't a valid decimal number at a place where it shouldn't expect a valid decimal number.
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post by Pupil »

Polo wrote:
3thing=128
128 is a "valid decimal number"
so "3thing" is the "not valid decimal number", but here it's a variable, so something's wrong somewhere.
Well it isn't a variable, is it! Why, because it doesn't follow PB's naming convention for variables.

Everything that starts with a number is considered to be a decimal of some sort by the compiler. if a non-numerical character(except operators and whitespace) is encountered in a character stream that starts with a numerical it's considered a non-valid number. That you perceive things differently can't be blamed on the compiler (Fred hasn't implemented the mind-reading code into the compiler yet). ;)
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post by Pupil »

Trond wrote:Try to type in 3thing on a line by itself. :wink: Also, "=" isn't a valid decimal number.
Already tried that, your point being?

Yes '=' isn't a valid decimal number, however it's a valid operator, but hopefully you already knew that.. ;)
The thing is: It reports that it got something which wasn't a valid decimal number at a place where it shouldn't expect a valid decimal number.
Exactly why shouldn't it expect a decimal number here?
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

well, sorry, but "3thing" should be reported as a wrong variable name, then :)
I just think it's not supported because Fred hasn't made the parser accept it, I think in other language using "3thing" is possible, come on, Fred, it's not that this is a really big feature we want, but it would make the language better ;)
Post Reply