[8.1] Possible bug with if statement

classic Classic list List threaded Threaded
35 messages Options
12
Reply | Threaded
Open this post in threaded view
|

[8.1] Possible bug with if statement

Anibal Escobar
Hello everyone.  In the following code, the if statement evaluates to
true when it shouldn't.

<?LassoScript
        var: 'discount' = 0;
        if: $discount == 'free shipping';
                var: 'freeShipping' = 'yes';
        else;
                var: 'freeShipping' = '';
        /if;
        $freeShipping;
?>

Changing the code so that $discount is another number or a string
allows the if statement to evaluate correctly.  Am I missing something?
  Can anyone replicate these results?

Thanks, Anibal Escobar


------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage
Reply | Threaded
Open this post in threaded view
|

Re: [8.1] Possible bug with if statement

Bil Corry-3
Anibal Escobar wrote:
> Hello everyone.  In the following code, the if statement evaluates to
> true when it shouldn't.

$discount is an integer, so Lasso converts 'free shipping' to an integer to compare.  Since (integer:'free shipping') == 0, and $discount is 0, the [if] statement is true.

Instead, do this:

    var: 'discount' = string;
    if: $discount == 'free shipping';
        var: 'freeShipping' = 'yes';
    else;
        var: 'freeShipping' = '';
    /if;
    $freeShipping;
 

- Bil



------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage
Reply | Threaded
Open this post in threaded view
|

Re: [8.1] Possible bug with if statement

Trevor Jacques
>$discount is an integer, so Lasso converts 'free shipping' to an
>integer to compare.

Lasso's treatment of null by converting it to zero has always bugged
me. The two are not the same, so a comparison of null in a numeric
var should not equal zero in a numeric field. There are similar
non-SQL-standard issue with Lasso's treatment of null data field on a
web page. Lasso developers just have to code around them.  :-/

null has a meaning, but, all to often, Lasso seems to think
otherwise. This can get really frustrating when one is debugging and
forgets Lasso's foibles....  :-(

T.

------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage
Reply | Threaded
Open this post in threaded view
|

Re: [8.1] Possible bug with if statement

Jolle Carlestam
In reply to this post by Bil Corry-3
One might wonder why it always have to be the integer that wins. If I  
try to put the string value first it still evaluate to true.
This turns out true:
        var: 'discount' = 0;
        var:'mytest' = 'mo mother';
        $mytest == $discount;

As this:
        var: 'discount' = 0.0;
        var:'mytest' = 'mo mother';
        $mytest == $discount;

But this will be false:
        var: 'discount' = '0';
        var:'mytest' = 'mo mother';
        $mytest == $discount;

I too would call that a bug.

And use a workaround:
        var: 'discount' = 0;
        if: $discount + '' == 'free shipping';
                var: 'freeShipping' = 'yes';
        else;
                var: 'freeShipping' = 'no';
        /if;
        $freeShipping;

And this was tested on 8.5.1 by the way.

HDB
JC

5 sep 2006 kl. 17.03 skrev Bil Corry:

> Anibal Escobar wrote:
>> Hello everyone.  In the following code, the if statement evaluates  
>> to true when it shouldn't.
>
> $discount is an integer, so Lasso converts 'free shipping' to an  
> integer to compare.  Since (integer:'free shipping') == 0, and  
> $discount is 0, the [if] statement is true.
>
> Instead, do this:
>
>    var: 'discount' = string;
>    if: $discount == 'free shipping';
>        var: 'freeShipping' = 'yes';
>    else;
>        var: 'freeShipping' = '';
>    /if;
>    $freeShipping;
> - Bil
>
>
>
> ------------------------------
> Lasso Support: http://support.omnipilot.com/
> Search the list archives: http://www.listsearch.com/lassotalk.lasso
> Manage your list subscription:  http://www.listsearch.com/ 
> lassotalk.lasso?manage


------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage
Reply | Threaded
Open this post in threaded view
|

Re: [8.1] Possible bug with if statement

Trevor Jacques
>And this was tested on 8.5.1 by the way.

I think it has more to do with the philosophy of the way Lasso is/has
been created, rather than specific bugs. I suspect that we will have
to accept that this is the way Lasso works and write our code
accordingly.  :-/

T.

------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage
Reply | Threaded
Open this post in threaded view
|

Re: [8.1] Possible bug with if statement

Greg Willits-2
In reply to this post by Trevor Jacques
On Sep 5, 2006, at 8:10 AM, Trevor Jacques wrote:

>> $discount is an integer, so Lasso converts 'free shipping' to an  
>> integer to compare.
>
> Lasso's treatment of null by converting it to zero has always  
> bugged me. The two are not the same, so a comparison of null in a  
> numeric var should not equal zero in a numeric field. There are  
> similar non-SQL-standard issue with Lasso's treatment of null data  
> field on a web page. Lasso developers just have to code around  
> them.  :-/
>
> null has a meaning, but, all to often, Lasso seems to think  
> otherwise. This can get really frustrating when one is debugging  
> and forgets Lasso's foibles....  :-(


Using == for loose equality is typical for a non-strongly typed  
language, so 0 == empty string is OK by me (saves a lot of type  
checkig hassle). BUT, even the === statements do not yield the  
correct result (Lasso 8.1), and that is wrong IMO. That's what the  
=== is for, when you do want that strongly typed equality test.

'<br>'; null === null;
'<br>'; null === 0;
'<br>'; null === '';
'<br>'; null === integer;
'<br>'; null === string;
'<br>'; null === array;
'<br>'; null === map;

true
true
true
true
true
false
false



-- gw
-----------------------------------------------------------------------
www.araelium.com/aredit/ae_and_lasso :: A new, Lasso-friendly, OS X
specific project manager and code editing developmennt application.
www.pageblocks.org :: A comprehensive application framework for Lasso.
-----------------------------------------------------------------------



------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage
Reply | Threaded
Open this post in threaded view
|

Re: [8.1] Possible bug with if statement

Paul Melia
In reply to this post by Trevor Jacques

On Sep 5, 2006, at 11:25 AM, Trevor Jacques wrote:

>> And this was tested on 8.5.1 by the way.
>
> I think it has more to do with the philosophy of the way Lasso is/
> has been created, rather than specific bugs. I suspect that we will  
> have to accept that this is the way Lasso works and write our code  
> accordingly.  :-/
>
> T.

C.J. Date, one of the creators of relational databases, makes an  
eloquent argument in his book "Database in Depth" that NULLs are poor  
compromise and should be avoided.

Since I read that book, I have ceased using NULLs in my database and  
have not had a problem like the one discussed.
I highly recommend the book.

FWIW,
Paul

------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage
Reply | Threaded
Open this post in threaded view
|

Re: [8.1] Possible bug with if statement

Trevor Jacques
In reply to this post by Greg Willits-2
>BUT, even the === statements do not yield the correct result (Lasso 8.1)

I could live with ===, if it worked (but the difference between how
Lasso treats == and === should be up front and center).  :-)

T.

------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage
Reply | Threaded
Open this post in threaded view
|

Re: [8.1] Possible bug with if statement

Trevor Jacques
In reply to this post by Paul Melia
>C.J. Date, one of the creators of relational databases, makes an
>eloquent argument in his book "Database in Depth" that NULLs are
>poor compromise and should be avoided.

I'd like to hear how he'd treat no entry in a web for a text field.
(Putting anything in the database when nothing was supplied is
constructing data where there were none. Not a good idea, I suspect.)

T.

------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage
Reply | Threaded
Open this post in threaded view
|

Re: [8.1] Possible bug with if statement

Greg Willits-2
In reply to this post by Paul Melia
On Sep 5, 2006, at 8:33 AM, Paul Melia wrote:

> On Sep 5, 2006, at 11:25 AM, Trevor Jacques wrote:
>
>>> And this was tested on 8.5.1 by the way.
>>
>> I think it has more to do with the philosophy of the way Lasso is/
>> has been created, rather than specific bugs. I suspect that we  
>> will have to accept that this is the way Lasso works and write our  
>> code accordingly.  :-/
>
> C.J. Date, one of the creators of relational databases, makes an  
> eloquent argument in his book "Database in Depth" that NULLs are  
> poor compromise and should be avoided.
>
> Since I read that book, I have ceased using NULLs in my database  
> and have not had a problem like the one discussed.
> I highly recommend the book.


Me too, except that what Trevor does is exactly why NULL exists, so I  
would expect his code to be full of correct null-specific usage.

For regular usage, fields should not allow null, but when you have to  
know the difference between data not available and data = empty or 0,  
then NULL is a necessity.

-- gw


------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage
Reply | Threaded
Open this post in threaded view
|

Re: [8.1] Possible bug with if statement

Trevor Jacques
>but when you have to know the difference between data not available
>and data = empty or 0, then NULL is a necessity.

Which, I suspect, is precisely why NULL is defined in the ANSI-SQL
standard. ;-)

T.

------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage
Reply | Threaded
Open this post in threaded view
|

Re: [8.1] Possible bug with if statement

Jolle Carlestam
In reply to this post by Greg Willits-2
5 sep 2006 kl. 17.28 skrev Greg Willits:
> so 0 == empty string is OK by me

Would be OK for me too. But I still think that
'non empty string' == 0 should evaluate to false.

And if 0 == 'non empty string' evaluates to true since the string is  
converted to integer
then 'non empty string' == 0 should convert the 0 to a string and  
evaluate to false.

HDB
JC


------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage
Reply | Threaded
Open this post in threaded view
|

Re: [8.1] Possible bug with if statement

decorior
In reply to this post by Trevor Jacques
Paul makes a good point. NULL seems to me to be historical but  
supported.

It is kind of like creating an object and not setting the instance  
variables in the constructor.

Sure, lasso could probably make the changes, but over time I think  
null will disappear.

Ouch! (flames in advance)

Deco
On Sep 5, 2006, at 9:48 AM, Trevor Jacques wrote:

>> but when you have to know the difference between data not  
>> available and data = empty or 0, then NULL is a necessity.
>
> Which, I suspect, is precisely why NULL is defined in the ANSI-SQL  
> standard. ;-)
>
> T.
>
> ------------------------------
> Lasso Support: http://support.omnipilot.com/
> Search the list archives: http://www.listsearch.com/lassotalk.lasso
> Manage your list subscription:  http://www.listsearch.com/ 
> lassotalk.lasso?manage


------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage
Reply | Threaded
Open this post in threaded view
|

Re: [8.1] Possible bug with if statement

Fletcher Sandbeck
On 2006-09-05 at 10:37 by [hidden email] (Deco Rior):

>Paul makes a good point. NULL seems to me to be historical but  
>supported.
>
>It is kind of like creating an object and not setting the instance  
>variables in the constructor.
>
>Sure, lasso could probably make the changes, but over time I think  
>null will disappear.

Lasso supports NULL in MySQL already.  [Field: 'myfield'] will return a Lasso null if the field contains NULL.  You can use -op='eq', 'myfield'=null to search for NULL values using IS NULL (and -op='neq' for IS NOT NULL).

[fletcher]
--
Fletcher Sandbeck                         [hidden email]
Director of Product Development       http://www.lassostudio.com
OmniPilot Software, Inc.                http://www.omnipilot.com

------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage
Reply | Threaded
Open this post in threaded view
|

Re: [8.1] Possible bug with if statement

Trevor Jacques
In reply to this post by decorior
>Ouch! (flames in advance)

:-)

>Sure, lasso could probably make the changes, but over time I think
>null will disappear.

That will never happen, because null is a basic, fundamental
construct needed by many people (including me). To those people there
is a fundamentally important difference between nothing and zero.
Heck, dbs like Oracle have other 'empty/not set' 'values.'

T.

------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage
Reply | Threaded
Open this post in threaded view
|

Re: [8.1] Possible bug with if statement

Trevor Jacques
In reply to this post by Fletcher Sandbeck
>Lasso supports NULL in MySQL already.  [Field: 'myfield'] will
>return a Lasso null if the field contains NULL.  You can use
>-op='eq', 'myfield'=null to search for NULL values using IS NULL
>(and -op='neq' for IS NOT NULL).

I think that the real problem for many of us is that we have to
specifically compare for nulls, rather than do a simple compare. In
the case of Lasso, a compare is not, necessarily, the compare one
thinks it is. I find this unfortunate.  :-/

T.

------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage
Reply | Threaded
Open this post in threaded view
|

Re: [8.1] Possible bug with if statement

Greg Willits-2
In reply to this post by Jolle Carlestam
On Sep 5, 2006, at 8:54 AM, [hidden email] wrote:

> 5 sep 2006 kl. 17.28 skrev Greg Willits:
>> so 0 == empty string is OK by me
>
> Would be OK for me too. But I still think that
> 'non empty string' == 0 should evaluate to false.
>
> And if 0 == 'non empty string' evaluates to true since the string  
> is converted to integer
> then 'non empty string' == 0 should convert the 0 to a string and  
> evaluate to false.


They should behave the same. 1 == 0 or 0 == 1. What's on the left or  
right of == should not matter. It's not a case of testing one type,  
then convert both to that type. It's a case that dissimilar types  
being cast to the same common type regardless of which one comes  
first in order to preserve the mathematical truth that left or right  
side does not matter.

BTW, PHP behaves the same as Lasso, but Python and Ruby do not.

With these three tests:

a = 0
b = 'hello'

a = 'hello'
b = 0

a = 0
b = ''

Lasso and PHP see them all as TRUE.

Python and Ruby see them all as FALSE.

However with ===, PHP sees them as false. This is where Lasso's bug is.


-- gw
-----------------------------------------------------------------------
www.araelium.com/aredit/ae_and_lasso :: A new, Lasso-friendly, OS X
specific project manager and code editing developmennt application.
www.pageblocks.org :: A comprehensive application framework for Lasso.
-----------------------------------------------------------------------



------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage
Reply | Threaded
Open this post in threaded view
|

Re: [8.1] Possible bug with if statement

Trevor Jacques
>Lasso and PHP see them all as TRUE.
>Python and Ruby see them all as FALSE.
>However with ===, PHP sees them as false. This is where Lasso's bug is.

Now that the situation is known for certain, it needs to be fixed.
Have you reported it to OP, yet?

T.

------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage
Reply | Threaded
Open this post in threaded view
|

Re: [8.1] Possible bug with if statement

Greg Willits-2
In reply to this post by Trevor Jacques
On Sep 5, 2006, at 9:44 AM, Trevor Jacques wrote:

>> Lasso supports NULL in MySQL already.  [Field: 'myfield'] will  
>> return a Lasso null if the field contains NULL.  You can use -
>> op='eq', 'myfield'=null to search for NULL values using IS NULL  
>> (and -op='neq' for IS NOT NULL).
>
> I think that the real problem for many of us is that we have to  
> specifically compare for nulls, rather than do a simple compare. In  
> the case of Lasso, a compare is not, necessarily, the compare one  
> thinks it is. I find this unfortunate.  :-/


Now you have me confused. Why is the the problem you see?

if NULL != 0 and NULL != '' (which is a good thing), then you would  
have to compare specifically for NULL, so why this a problem?

-- gw


------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage
Reply | Threaded
Open this post in threaded view
|

Re: [8.1] Possible bug with if statement

Greg Willits-2
In reply to this post by Trevor Jacques

On Sep 5, 2006, at 9:59 AM, Trevor Jacques wrote:

>> Lasso and PHP see them all as TRUE.
>> Python and Ruby see them all as FALSE.
>> However with ===, PHP sees them as false. This is where Lasso's  
>> bug is.
>
> Now that the situation is known for certain, it needs to be fixed.  
> Have you reported it to OP, yet?


Actually hang on... that's not the scenario I think Lasso is wrong with.

This is the one I think Lasso is wrong with:

'<br>'; null === null;
'<br>'; null === 0;
'<br>'; null === '';
'<br>'; null === integer;
'<br>'; null === string;
'<br>'; null === array;
'<br>'; null === map;

true
true
true
true
true
false
false

IMO, only that first one should be true.

-- gw



------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage
12