Page 4 of 4
Re: Strict Syntax Checking for Scripts
Posted: 06 May 2015 16:04
by TheQwerty
Admittedly, it's not really a syntax error but any chance this feature could detect and warn when the variables within a
while's expression are not updated within the
while block?

Re: Strict Syntax Checking for Scripts
Posted: 06 May 2015 16:16
by admin
TheQwerty wrote:Admittedly, it's not really a syntax error but any chance this feature could detect and warn when the variables within a
while's expression are not updated within the
while block?

To pamper a coder...

... come on...
Re: Strict Syntax Checking for Scripts
Posted: 06 May 2015 16:19
by TheQwerty
admin wrote:TheQwerty wrote:Admittedly, it's not really a syntax error but any chance this feature could detect and warn when the variables within a
while's expression are not updated within the
while block?

To pamper a coder...

... come on...
I'm embarrassed to admit the number of times I've lost code entered into Run Script because I've made this error and had to eventually kill XY.
EDIT: Of course it's happened so much I can't keep count anyhow. /edit.
There's a lot of lessons to learn there, but if experience has taught me anything it's that I'm never going to learn.

Re: Strict Syntax Checking for Scripts
Posted: 06 May 2015 16:23
by admin
TheQwerty wrote:... but if experience has taught me anything it's that I'm never going to learn.

That's a good one.

Re: Strict Syntax Checking for Scripts
Posted: 06 May 2015 16:30
by Filehero
admin wrote:That's a good one.

Oh yes, the camouflage
while(true) lock.

Re: Strict Syntax Checking for Scripts
Posted: 06 May 2015 16:59
by bdeshi
I've learnt a great trick from [ed.]
somebody here Ken ,
Code: Select all
$c = 10; while ($c-- >= 0) {echo $c;}
it's a lifesaver!

Re: Strict Syntax Checking for Scripts
Posted: 06 May 2015 23:49
by PeterH
SammaySarkar wrote:admin wrote:You have a non-weird use of Eval() where any quotes should be added? I doubt it.
Oh sure, found 35 cases where eval() usage will cause syntax hiccups.
Here's one example:
Code: Select all
$varBaseName_1 = 'value1'; $DynamicPart = '1';
eval($varBaseName_$DynamicPart);
most cases have similar eval() usage, used to build and obtain a dynamic variable value.
btw, about that auto-quoting: if this is introduced, maybe it should be restricted to in places like this where running-as-is will cause fatal abortion.
Hm - what do you want to show with this? I don't understand...
Both examples are simply illegal syntax!
In first example:
eval($varBaseName_$DynamicPart);
the operand for eval is "a kind of" list of 2 variables, without an operator between them, like . or +, so illegal.
And the first of it's 2 variables even isn't initialized - it's $varBaseName_ so non-resolved by it's value, but just by it's name.
In Don's mod with double quotes it's a string, with variables "simply resolved". Again the 1st is resolved by it's name, the 2nd by it's value, and both concatenated. Happens to look quite nice, but try a modification: add a line
Code: Select all
$varBaseName_1 = 'value1'; $DynamicPart = '1';
$varBaseName_ = 'strange';
Echo eval($varBaseName_$DynamicPart);
Is the result what you expect? But you could try:
Echo eval('$varBaseName'."_$DynamicPart");
(I don't see how XY could auto-add these quotes and the dot in a correct way.)
The 2nd example resolves to something like:
$d = c:\prog\xydir;
You know that \ is the operator for integer division? Hm.
Try: Echo 20\3;
Or: Echo "20\3";
Or: Echo Eval("20\3");
Re: Strict Syntax Checking for Scripts
Posted: 07 May 2015 06:34
by bdeshi
in 1st example eval is used to get a variable dynamically. Say these are all set: $var_1, $var_2, ...,$var34. & $Dyn = 1; Just by changing $Dyn, eval($var$Dyn) can return any of those vars by a single stmt.
It's not a question of it being a bad syntax, I just saw a lot of examples, and I was getting so many dubious errors.
2nd example: I know it will be bad. But if the string didn't have \,/ etc, it would've returned right. But my example will cause overflow. So I suggested XY might add quotes in these cases.
Re: Strict Syntax Checking for Scripts
Posted: 07 May 2015 11:32
by PeterH
Did you try to understand what I have written?
You want to refer to a dynamic variable like $name_##.
For the created name of that variable $name_ is *constant*, while ## is *variable*.
If you write eval($varBaseName_$DynamicPart), you want the first part to be a constant string, but $varBaseName_ is a variable! (Note: the trailing _ is part of the name!!!) *If* you have never filled it, *then* it's undefined, and as such *happens to* return it's name as it's "contents". So, for what you want, this part *must* be in single quotes to be meant as constant. (Especially the $, otherwise saying it's a variable!)
The 2nd part is meant to be variable - so it *may not* be in single quotes. There are different versions how to do - the 1st example seems the best to me:
Echo eval('$varBaseName_ ' . $DynamicPart );
Echo eval('$varBaseName_' . "$DynamicPart");
Echo eval('$varBaseName' . "_$DynamicPart");
Echo eval('$' . "varBaseName_$DynamicPart");
So could you tell me, how XY could have guessed that you meant this?
The result: syntax is there to regulate how you tell the XY interpreter what you want it to do.
Re: Strict Syntax Checking for Scripts
Posted: 07 May 2015 14:28
by bdeshi
I agree with you, but there was a misunderstanding somewhere. But let's just forget the whole matter.
I know it's bad syntax, and I'm not suggesting anyone should be using it.