mIRC Home    About    Download    Register    News    Help

Topic Options
#100762 - 16/10/04 09:20 AM about regexes again
Leoric Offline
Ameglian cow

Registered: 11/04/04
Posts: 48
Loc: Natal, Brasil
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:

Code:
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:

Code:
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

Top
#100763 - 16/10/04 10:47 AM Re: about regexes again
Leoric Offline
Ameglian cow

Registered: 11/04/04
Posts: 48
Loc: Natal, Brasil
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

Top
#100764 - 16/10/04 01:32 PM Re: about regexes again
starbucks_mafia Offline
Hoopy frood

Registered: 09/12/02
Posts: 2962
Loc: Norwich, UK
The workaround:
Code:
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.

Top
#100765 - 16/10/04 01:45 PM Re: about regexes again
Sigh Offline
Fjord artisan

Registered: 28/08/03
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

Top
#100766 - 16/10/04 09:27 PM Re: about regexes again
Leoric Offline
Ameglian cow

Registered: 11/04/04
Posts: 48
Loc: Natal, Brasil
thanks starbucks and sigh grin
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 smirk

about the factorial (its "fac" in english? i suggest $fat because here i say "fatorial", blush ), let me dream a little. what about an $calc_ext that is a little more slow but can do operations with large numbers? laugh (ok, its nonsense frown frown )
_________________________
__________
dark_light @ irc.brasnet.org

Top