|
Joined: Apr 2004
Posts: 48
Ameglian cow
|
OP
Ameglian cow
Joined: Apr 2004
Posts: 48 |
i was trying to make a $rp_mod that transforms this string: (|-2|+1)/|-3| in this string: (2+1)/3, so i begin making a alias like this: alias rp_mod {
var %x = $1, %y = $regsub($1, /\|([^|]*)\|/g, \1, %x))
return %x
} it only removes the |'s, but i cant do just $abs(\1) or anything like this. so, i want a $\n ident, like $\1, for use in this cases. the alias might be like this: alias rp_mod {
var %x = $1, %y = $regsub($1, /\|([^|]*)\|/g, $abs($\1), %x))
return %x
} ps: anybody knows how i can do this? pps: how about the || built-in in the $calc identifier?
__________ dark_light @ irc.brasnet.org
|
|
|
|
Joined: Apr 2004
Posts: 48
Ameglian cow
|
OP
Ameglian cow
Joined: Apr 2004
Posts: 48 |
by the way..
an $fat(n) (or anything like this) that returns n!, the same of $calc(1*2*3*4...*n) would be very nice. if i can do $fat(2.6), using the gamma function, would be even better. and a $calc(3!/2!) would be definitively W-O-N-D-E-R-F-U-L, really helping me with a rapid resolution for math problems ^_^
ps: i alredy know that n! can be scripted, but it seems very slowly for large values of n
__________ dark_light @ irc.brasnet.org
|
|
|
|
Joined: Dec 2002
Posts: 2,962
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 2,962 |
The workaround: alias rp_mod {
var %x = $1, %y = $regsub($1, /\|[color:red]-?[/color]([^|]*)\|/g, \1, %x))
return %x
}
Spelling mistakes, grammatical errors, and stupid comments are intentional.
|
|
|
|
Joined: Aug 2003
Posts: 314
Fjord artisan
|
Fjord artisan
Joined: Aug 2003
Posts: 314 |
The ability to evaluate identifiers after substitutions in $regsub is a good idea, but has also been requested several times before. One workaround that can be used is having the identifiers escaped in the subtext and evaluating your result variable twice:
alias rp_mod { var %x = $1, %y = $regsub($1, /\|([^|]*)\|/g,$cr \$+ \$abs(\$calc(\1)) \$+ $cr, %x)) return $remove($(%x,2),$cr) }
Of course if you don't expect there to be any calculations in the modulus function then you could just adapt your original alias slightly:
alias rp_mod { var %x = $1, %y = $regsub($1, /\|-?(.+?)\|/g, \1, %x)) return %x }
So it removes the hyphen without substituting it back in. But I assume you expect there to be calculations such as |2-3| present in which case the first alias would be the better option
With the double evaluation of %x there's always the problem that you might be evaluating other parts of a string you don't want to be, or removing $cr in places you don't want to so in this case I'd use a loop with $regex:
alias rp_mod { var %x = $1 while ($regex(%x,(\|(.+?)\|))) %x = $replace(%x,$regml(1),$abs($calc($regml(2)))) return %x }
Those are just some workarounds to keep in mind until the feature you suggested may be added. As for the factorial identifier, you're right in saying it can be scripted but it would become inaccurate before slow since by the time 1000! is hit, it would require 1000 iterations each involving a simple mathematical operation which can be handled quite quickly, but due to the limitation of mIRC's calc functions it would be inaccurate
|
|
|
|
Joined: Apr 2004
Posts: 48
Ameglian cow
|
OP
Ameglian cow
Joined: Apr 2004
Posts: 48 |
thanks starbucks and sigh i was trying to do a while with $regex and $regsub, but it dont works (maybe i have made a mistake) i will try your while, sigh, it seems to be what i need about the factorial (its "fac" in english? i suggest $fat because here i say "fatorial", ), let me dream a little. what about an $calc_ext that is a little more slow but can do operations with large numbers? (ok, its nonsense )
__________ dark_light @ irc.brasnet.org
|
|
|
|
|