mIRC Home    About    Download    Register    News    Help

Topic Options
#212968 - 12/06/09 08:48 AM $right with negative index returning $null?
s00p Offline
Fjord artisan

Registered: 01/07/08
Posts: 236
Loc: Hell, Australia
In any other language that allows negative numbers to be an inverse index for $left and $right, something like $right(a,-1) would return a. Is it intentional that mIRC returns $null in this case? This only seems to happen for strings where the length is 1.

Top
#212970 - 12/06/09 12:17 PM Re: $right with negative index returning $null? [Re: s00p]
RusselB Offline
Planetary brain

Registered: 03/08/04
Posts: 7252
Loc: Ontario, Canada
From the help file
Quote:
If N is a negative value, it returns all but N characters.
Noting the bolded word, what you are noting is intentional.

1 - 1 = 0. I suppose Kahled could've made it return 0 rather than $null.

Top
#212981 - 12/06/09 06:45 PM Re: $right with negative index returning $null? [Re: s00p]
argv0 Offline
Planetary brain

Registered: 13/10/03
Posts: 3918
Loc: Montreal, QC, Canada
In any other language (well, not any) the base index starts at 0. Is this also justification to change mIRC? Because mIRC starts indexes at 1 by convention, it makes sense for -1 to behave differently from the "other languages" you're referring to where the base is 0.
_________________________
- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"

Top
#213053 - 16/06/09 02:09 PM Re: $right with negative index returning $null? [Re: argv0]
s00p Offline
Fjord artisan

Registered: 01/07/08
Posts: 236
Loc: Hell, Australia
No, it's completely unrelated. What is -0 in any other language? They've gone through with the inconsistency of any non-zero index at all. What I'm complaining about is strange, and makes things difficult. The mere fact that it's strange behaviour to me makes it a bug in my mind.

I have another one for you. No use denying this one: $and(1111,16) == STUPID!


Edited by s00p (16/06/09 02:11 PM)

Top
#213054 - 16/06/09 02:50 PM Re: $right with negative index returning $null? [Re: s00p]
genius_at_work Offline
Hoopy frood

Registered: 08/10/05
Posts: 1741
What is stupid about it?

Boolean AND Logic Table:

Code:

1 & 1 = 1
0 & 1 = 0
1 & 0 = 0
0 & 0 = 0



Therefore:

Code:

 1111d = 10001010111b
 0016d = 00000010000b
&--------------------&
         00000010000b = 0016d



-genius_at_work

Top
#213055 - 16/06/09 03:10 PM Re: $right with negative index returning $null? [Re: s00p]
Wims Offline
Planetary brain

Registered: 31/07/06
Posts: 3436
Loc: France
What the point comparing to other language ?
As stated by the help file, when a negative value is used, it return all BUT N characters, then :

$right(abc,-1) return bc
$right(ab,-1) return b
Do you expect $right(a,-1) to return 'a' now ? This would make inconstistency.
Quote:
The mere fact that it's strange behaviour to me makes it a bug in my mind.
I don't call a strange behavior something that respect what the help file say.If you don't like the behavior it's another story, but to answer your question, yes the behavior is intentional.
_________________________
Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net

Top
#213056 - 16/06/09 05:30 PM Re: $right with negative index returning $null? [Re: genius_at_work]
s00p Offline
Fjord artisan

Registered: 01/07/08
Posts: 236
Loc: Hell, Australia
woah, duh. I really should think about what I write more often.

Top
#213063 - 16/06/09 06:53 PM Re: $right with negative index returning $null? [Re: s00p]
argv0 Offline
Planetary brain

Registered: 13/10/03
Posts: 3918
Loc: Montreal, QC, Canada
I'm not sure what your comparison is. "They've gone through with the inconsistency" -- who is "they"? do you have an example where a language with a non-zero base index solves this problem?
_________________________
- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"

Top