Macro loops
Posted by: JohnHell
Date: August 27, 2008 12:21AM

Hi,

I come to ask because I never noticed before. Maybe the thing is normal for programmers but as I'm not one it is curious for me.

Well, the thing is that negative loops can't be concatenated but positive can. Lets see some examples:
$a = $b != $c ? $d : $b != $c ? $d : $b != $c ? $d : $x; <<<--- this, doesn't work

$a = $b != $c ? $d : $b == $c ? $d : $b == $c ? $d : $x; <<<--- this works

$a = $b == $c ? $d : $b != $c ? $d : $b == $c ? $d : $x; <<<--- this works

$a = $b == $c ? $d : $b == $c ? $d : $b == $c ? $d : $x; <<<--- this of course works

I'm still working on 1.1.6 so maybe is that, but just I want to know smiling smiley It is the first time I did several negative loops together and it just was my doubt.

Re: Macro loops
Posted by: desga2
Date: August 27, 2008 03:46AM

Are you tried with "()":
$a = ($b != $c) ? $d : ($b != $c) ? $d : ($b != $c) ? $d : $x; <<<--- this, doesn't work

Tomorrow i'll tested it and i say you if works in 1.5.

K-Meleon in Spanish



Edited 1 time(s). Last edit at 08/27/2008 03:48AM by desga2.

Re: Macro loops
Posted by: JohnHell
Date: August 27, 2008 04:10AM

Hey, remember it is in example I mean, the macros above aren't correct (there shouldn't be checks for the same variable, for example, if you really are doing conditionals), you can't check every time if b!=c ;)

Re: Macro loops
Posted by: JamesD
Date: August 27, 2008 07:00AM

I can find no error in the code. Here is my test. If any of the three iterations is true the answer is 3 else the answer is 4. I tested with $b and $c equal and unequal.

$b = 1; 
$c = 2; 
$d = 3; 
$x = 4 ;

#<<<--- this, doesn't work
$a = $b != $c ? $d : $b != $c ? $d : $b != $c ? $d : $x;
#when b&c are 1 a equal 4 %%% 1st false 2nd false 3rd false
#when b=1 and c=2 a equal 3 %%% 1st true
 alert($a, "first value of $a");
 
#<<<--- this works
$a = $b != $c ? $d : $b == $c ? $d : $b == $c ? $d : $x;
#when b&c are 1 a equal 3  %%% 1st false 2nd true
#when b=1 and c=2 a equal 3  %%%  1st true
  alert($a, "second value of $a");
  
#<<<--- this works
$a = $b == $c ? $d : $b != $c ? $d : $b == $c ? $d : $x;
#when b&c are 1 a equal 3  %%%  1st true 
#when b=1 and c=2 a equal 3 %%%  1st false 2nd true
 alert($a, "third value of $a");
 
#<<<--- this of course works
$a = $b == $c ? $d : $b == $c ? $d : $b == $c ? $d : $x;
#when b&c are 1 a equal 3  %%% 1st true
#when b=1 and c=2 a equal 4 %%%  1st false 2nd false 3rd false
 alert($a, "fourth value of $a");
 
##Are you tried with "()":
$a = ($b != $c) ? $d : ($b != $c) ? $d : ($b != $c) ? $d : $x;
#when b&c are 1 a equal 4  %%% 1st false 2nd false 3rd false
#when b=1 and c=2 a equal 3 %%% 1st true
 alert($a, "fifth value of $a");



Edited 1 time(s). Last edit at 08/27/2008 07:07AM by JamesD.

Re: Macro loops
Posted by: JohnHell
Date: August 27, 2008 07:40AM

Let me say something, because I think this could be confusing if someone doesn't read correctly. I hope you aren't using the same code as I posted before, I mean, using the same conditional three times. Let me post an expanded code:

$a = $b != $c ? $d : $b != $c ? $d : $b != $c ? $d : $x;
THE ABOVE IS WRONG TO USE AS CONDITIONAL, JUST WAS AN EXAMPLE OF WHAT I MEAN WITH MORE THAN ONE NEGATION USE

This is only to put values to the code, nothing else.
$a = 0;
$b = 1;
$c = 2;
$d = 3;
$x = 4;
$y = 5;

$a = $b != $c ? $y : $b != $d ? $y : $c != $d ? $y : $x;
THE ABOVE IS CORRECT NOW

First condition: $a should take the value of $y if $b is not equal to $c, correct. The result is that $a now is 5.

Second condition: $a should take the value of $y if $b is not equal to $d, correct. The result is that $a now is 5.

Third condition: $a should take the value of $y if $c is not equal to $d, correct. The result is that $a now is 5.

If not of the above: $a now is 4

Ok, what I came here with, is that no one of the three conditions are used and $a ever takes the value of $y, even if in the first condition, $b is equal to $c, in the second, $b is equal to $d and in the third, $c is equal to $d, never is taken $x for a value for $a.

But, if instead 3 negative conditions, only one of the conditions is negative, all works.

So, what I was telling is that 3 negative conditions one "behind" another, doesn't work.



Edited 2 time(s). Last edit at 08/27/2008 07:43AM by JohnHell.

Re: Macro loops
Posted by: desga2
Date: August 27, 2008 07:45PM

I tried your code in 1.5 and nothing is wrong. All result are correct:
$b = 1; 
$c = 2; 
$d = 3; 
$x = 4 ;

#<<<--- this, doesn't work
$a = $b != $c ? $d : $b != $c ? $d : $b != $c ? $d : $x;
#when b&c are 1 a equal 4 %%% 1st false 2nd false 3rd false
#when b=1 and c=2 a equal 3 %%% 1st true
 alert($a, "first value of $a");

# Alert show a=3, this is correct, B and C are differents A=D=3, rest of expresion aren't evaluated because the first is true and a true value in first only asign A=D

# If B=C=1 then A=X=4 because 1st false 2nd false 3rd false

I don't know because you think this is wrong.
In my own opinion this is a stupid code because you ever check the same expresion:
$b != $c ?
And this expresion not changed it's the same that the first and you ever asign it the same value D if this is true and X if finally is false.
I wrote this line of code:
$a = $b != $c ? $d : $x;

It's possible that you are thinking in do some similar to this:
$a = $b != $c ? $d : $b != $d ? $c : $b != $x ? $d : $c;
#when b&c are 1 a equal 1  %%% 1st false 2nd true 3rd not checked
#when b=1 and c=2 a equal 3 %%% 1st true

# Or something like this:
$a = $b != $c ? ($b != $d ? $c : $d) : ($b != $x ? $d : $c);

K-Meleon in Spanish



Edited 1 time(s). Last edit at 08/27/2008 07:57PM by desga2.

Re: Macro loops
Posted by: JamesD
Date: August 27, 2008 07:57PM

It all depends on the data.
$a = 0;
$b = 1;
$c = 1;
$d = 1;
$x = 4;
$y = 5;
With this data the answer is 4. The code does exactly what it is supposed to do. With the original data, the first condition is true and nothing to the right of the : is executed.

Re: Macro loops
Posted by: JohnHell
Date: August 27, 2008 09:52PM

I haven't read your two latest posts. You are correct, of course, whatever, sure.

I'm stupid, after switching off the computer I realized it...

Forget this threat, only a bad nightmare U_U

Any solution is correct, but the conditionals I was using, as are negative create a "problem" (only in my mind), that needs to return the same result, because I'm stuuuuuuupid and I didn't get before :/

EDIT: I have to test your last statement desga, because I haven't used brackets yet,

$a = $b != $c ? ($b != $d ? $c : $d) : ($b != $x ? $d : $c);

I'm stuuuupid :/



Edited 2 time(s). Last edit at 08/27/2008 09:59PM by JohnHell.

Re: Macro loops
Posted by: desga2
Date: August 27, 2008 10:13PM

smiling smiley Not problem, everyone have stupid days when start program in a new language.
You take a pause or let it to next day to see the problem with mind more cleared.

K-Meleon in Spanish

Re: Macro loops
Posted by: JohnHell
Date: August 27, 2008 11:09PM

Well, is not a new language for me now, but maybe you are right and I had a bad day.

This happens because I hate how webpages handles things and I have... I can't say how many macros to control the way I browse.

Thank god:

"K-meleon, the browser you control" smiling smiley

Re: Macro loops
Posted by: disrupted(unlogged)
Date: August 27, 2008 11:23PM

i think the slogan should change:
"k-meleon, the browser that makes you a programmer" smiling smiley

Re: Macro loops
Posted by: JohnHell
Date: August 28, 2008 01:39AM

Lol, good point of view ;)

K-Meleon forum is powered by Phorum.