mIRC Home    About    Download    Register    News    Help

Print Thread
about regexes again #100762 16/10/04 08:20 AM
Joined: Apr 2004
Posts: 48
L
Leoric Offline OP
Ameglian cow
OP Offline
Ameglian cow
L
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:

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
Re: about regexes again #100763 16/10/04 09:47 AM
Joined: Apr 2004
Posts: 48
L
Leoric Offline OP
Ameglian cow
OP Offline
Ameglian cow
L
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
Re: about regexes again #100764 16/10/04 12:32 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
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.
Re: about regexes again #100765 16/10/04 12:45 PM
Joined: Aug 2003
Posts: 314
S
Sigh Offline
Fjord artisan
Offline
Fjord artisan
S
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

Re: about regexes again #100766 16/10/04 08:27 PM
Joined: Apr 2004
Posts: 48
L
Leoric Offline OP
Ameglian cow
OP Offline
Ameglian cow
L
Joined: Apr 2004
Posts: 48
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