-->
Page 1 of 1

Spaces in expressions

PostPosted: Sun May 07, 2017 9:51 pm
by ex-egll
Page 80 of the Basic Language Reference says in part:
"Spaces are don’t care :
A = 5 + 3 is the same as a=5+3"

I realise this is to do with comparisons in this instance, but I just spent a while trying to debug a very simple programme and the issue turned out to be due to spaces.

using a as a variable:
Initially variable a had a value of 1234, I wanted to increment this value within a loop so I used a=a+1; the value did not increment.
There were other factors involving sending the value of a in a udp packet and I thought initially the problem was somehow involved in that, after all a=a+1 is simple, right?

I then added spaces in the expressions
a=a+1 became a = a + 1 and it worked. I played around a little and found that as long as there was a space between a and = all was fine e.g.
a =a+1 would work

my curiosity was piqued now so, remembering back to early days of basic (40+years ago!!) I remember one strain of basic would not allow single character variables so I tried aa as the variable. In this case, any combinations of spaces worked e.g.
aa=aa+1
aa=aa + 1
aa = aa + 1 etc

Not sure whether this is a bug or not?

Re: Spaces in expressions

PostPosted: Mon May 08, 2017 12:02 pm
by bugs
ex-egll wrote:Page 80 of the Basic Language Reference says in part:
<snip>
Not sure whether this is a bug or not?


To my mind it is a bug - there is something very peculiar about the "=" symbol.
I started a thread some time ago where the "=" was supposed to be in a string but was getting clobered.
The last is post here:-
http://www.esp8266.com/viewtopic.php?f=42&t=13232&start=8

Re: Spaces in expressions

PostPosted: Sun May 14, 2017 4:04 am
by PhilTilson
That's a very interesting observation by ex-egll concerning variables having more than one character.

I have been complaining about the inconsistent treatment of spaces for some time and agree that there is definitely a bug here. Still, I shall test out the hypothesis and, if I can replicate it, will make sure I use two or more characters for variable names from now on!

Phil