Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD Beta Forum
dbosst
Apprentice


Joined: 15 Jun 2010
Posts: 121

PostPosted: Mon Aug 09, 2010 6:46 pm   

3.22 %null
 
I've used a mixture of %null(%1) and %1 == %null, and found today this problem:

This does not work fine:
#if (0 == %null) {#show {0 is null!}}

This works fine:
#if (%null(0)) {#show {0 is null!}}

the comparison of the integer 0 against %null fails in the first case
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Mon Aug 09, 2010 7:57 pm   
 
The first thing to realize is that the two statements are not the same.

%null is a predefined Variable that represents an empty variable value. %null() is a function that returns true if string is the null string. If string is left out then it returns a null string. That said there is a little something wonky, or at the very least counterintuitive, going on here.

Now consider the following:
Code:
#if (0 == %null) {#show {0 is null!}} {#show {Oops I guess not}}
#if (%null(0)) {#show {0 is null!}} {#show {Zero and nothing are not equivalent}}
#if (%null("")) {#show {Nothing is nothing}} {#show {Err... nothing is something??}}
#if (%null()) {#show {Let's go here}} {#show {There is no there there}}
#if (%null == %null) {#show {0 is null! 2}} {#show {Oops I guess not 2}}
#if ("" == %null) {#show {0 is null! 3}} {#show {Oops I guess not 3}}


In the second IF statement the argument to %null() is converted to a string, thus 0 becomes "0" which is of course not a null or empty string.

I would suggest you always use the function call unless you know you are always getting a string
_________________
Asati di tempari!
Reply with quote
dbosst
Apprentice


Joined: 15 Jun 2010
Posts: 121

PostPosted: Mon Aug 09, 2010 8:18 pm   
 
The problem I have is with the first case, though, I understand what you are saying.. my point is, if %null is representing an empty variable.. than comparing integer 0 to %null should always be false!
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Tue Aug 10, 2010 1:49 am   
 
%null() == 0 == FALSE == ""

so the first statement is correct. The above 4 items are equal because CMUD is a typeless language and is doing "autotype" stuff in the background.

As Tech mentioned, in the second case, %null takes a STRING argument, so %null(0) is the same as %null("0") and since "0" is NOT a null string, then it returns false.

So the second statement is also correct.
Reply with quote
dbosst
Apprentice


Joined: 15 Jun 2010
Posts: 121

PostPosted: Tue Aug 10, 2010 12:43 pm   
 
oh so %null() is interpreted to be equivalent to false (0) in a logical comparison, that's what was confusing me ... I thought %null() would be interpreted as actually nothing but not logically false, I guess I will stick to the second syntax then since this is a bit unusual to me
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Tue Aug 10, 2010 3:53 pm   
 
Yep, exactly. Because with *boolean* logic, all you have is True or False. "nothing" doesn't exist in boolean logic.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD Beta Forum All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net