|
Joined: Feb 2003
Posts: 2,812
Hoopy frood
|
OP
Hoopy frood
Joined: Feb 2003
Posts: 2,812 |
I don't know why this has never found its way into mIRC, but one of the most obnoxious things about creating custom aliases is the inclusion of default parameters and all the $iif() mess that goes with it. Rather than Alias XYZZY {
var %foo = $iif($1 != $null,$1,42)
var %bar = $iif($2-,$2-,and everything)
} I'd like to see Alias PLUGH {
var %foo = $1="42"
var %bar = $2-="and everything"
} I know this touches on some parsing fundamentals, but I'm convinced it's similar enough to other like-syntax in mSL that it works. For instance, $?1="pick a number" is almost identical in this regard. $1="42" just feels natural; like it belongs.
Well. At least I won lunch. Good philosophy, see good in bad, I like!
|
|
|
|
Joined: Mar 2010
Posts: 146
Vogon poet
|
Vogon poet
Joined: Mar 2010
Posts: 146 |
You know there is a /tokenize command, right?
Nothing...
|
|
|
|
Joined: Oct 2004
Posts: 8,330
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,330 |
That really wouldn't make much sense. You are considering a single situation... a null check. However, if you wanted that kind of feature, it would really need to work with any kind of check. But your example wouldn't work for anything else because you're not saying what you are checking. IF/$IIF are fine for this.
Invision Support #Invision on irc.irchighway.net
|
|
|
|
Joined: Feb 2003
Posts: 2,812
Hoopy frood
|
OP
Hoopy frood
Joined: Feb 2003
Posts: 2,812 |
It works the SAME as $?1="Enter Input". So, yes, feature works in all situations.
Well. At least I won lunch. Good philosophy, see good in bad, I like!
|
|
|
|
Joined: Oct 2004
Posts: 8,330
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,330 |
$?="" is an input. It doesn't work like $iif. $iif (and IF for that matter) compare 2 values and do something based on whether or not the comparison is true or false. $?="" just gets a value. They are completely different things.
You're looking at it only with null and saying that $iif($1 != $null,$1,some default value) would be the same as $1=some default value. How then would you write that if the $iif() was: $iif($1 != 5,$1,some default value) ? Your example of $1=some default value doesn't consider anything except null and wouldn't work for something else such as the 5 is in this example. Where would you put the 5 in your code?
How would you even read it? An IF/ELSEIF/ELSE or $IIF() can be read and makes sense when you read it... If X is true, then do this, else do that. Or, if X is true, use this value, else use that value. Your example basically says the variable equals one value equals another value. It really doesn't make much sense and I can't think of any language that uses anything like that syntax for comparing 2 items and setting a variable 2 different ways based on the result of that comparison.
Invision Support #Invision on irc.irchighway.net
|
|
|
|
Joined: Apr 2010
Posts: 969
Hoopy frood
|
Hoopy frood
Joined: Apr 2010
Posts: 969 |
This is actually similar to javascript's "OR" operator(not to be confused with operand). I believe what Raccoon is asking for is something that does "first non-null/0/false" assignment. var %a = $false||0||$null|hi
//this is true
if (%a === hi) return $true edit: nvm. after rereading the OP, it seems he wants to assign an alternative value if none is specified
Last edited by FroggieDaFrog; 03/05/13 08:22 PM.
|
|
|
|
Joined: Oct 2004
Posts: 8,330
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,330 |
Actually, that got me thinking of it differently. It sounds more like an ISNULL check rather than an IF check. That wouldn't be a bad option to have built in, but it's also extremely easy to script...
alias isnull {
if ($1 == $null) { return $2 }
else { return $1 }
}
Use: //var %x = $isnull($1,default) If $1 is null, then it will set the variable to whatever is entered as the default value. Otherwise, the variable is set to $1. As far as the original feature request, I see value in a built-in $isnull even if it's easy to script (and is really just about the same thing as $iif()), but that isn't really a replacement for $iif() because as I originally mentioned, it is specifically designed for checking on $null and not for checking on anything else.
Invision Support #Invision on irc.irchighway.net
|
|
|
|
Joined: Feb 2003
Posts: 2,812
Hoopy frood
|
OP
Hoopy frood
Joined: Feb 2003
Posts: 2,812 |
$?="" is an input. It doesn't work like $iif. $iif (and IF for that matter) compare 2 values and do something based on whether or not the comparison is true or false. $?="" just gets a value. They are completely different things.
Riamus2: I'm not looking to replace $iif. I'm suggesting exactly that -- a default value. If you need something more advanced, use $iif. $1="foo" would be same as $?1="type foo" but without the input box.
Well. At least I won lunch. Good philosophy, see good in bad, I like!
|
|
|
|
Joined: Oct 2012
Posts: 164
Vogon poet
|
Vogon poet
Joined: Oct 2012
Posts: 164 |
That would break scripts that rely on the existing behaviour of being able to append data to $N identifiers. //tokenize 32 foo | var -s %foo = $1="bar"
The suggestion offered by Riamus is easy enough and breaks nothing. alias isnull return $iif($1,$1,$2) //var -s %foo = $isnull($1,42),%bar = $isnull($2,and everything)
|
|
|
|
Joined: Oct 2003
Posts: 3,918
Hoopy frood
|
Hoopy frood
Joined: Oct 2003
Posts: 3,918 |
The proposed syntax wouldn't work but the concept *IS* useful.
This could work as Riamus suggested, but perhaps with a better name, like $default:
var %x = $default($1, DEFAULT_VALUE)
That wouldn't rely on any grammar modifications, which means it would work everywhere, not just in /set and /var:
//echo -a You are $default(%age, 0) years old.
That said, it's so simple to implement that having a builtin for this seems a little unnecessary. Most people don't need this.
- argv[0] on EFnet #mIRC - "Life is a pointer to an integer without a cast"
|
|
|
|
Joined: Oct 2004
Posts: 8,330
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,330 |
Yeah, $default works as well. However it is named, it is very easy to do in a script. I wouldn't be against it being added as a built-in identifier, but I also don't think it's really a big deal because it can be done using a very short piece of code.
Invision Support #Invision on irc.irchighway.net
|
|
|
|
|