mIRC Home    About    Download    Register    News    Help

Topic Options
#264120 - 30/10/18 05:19 AM block variable evaluation cleaner
Talon Offline
Vogon poet

Registered: 09/12/02
Posts: 191
Loc: Ohio, USA
quite often times if you need things not to evaluate, such as within a timer, you use $!<identifier>.

I think it would be handy for variables to also support this for cleaner, easier to follow code, without having to do like % $+ <varname> or $eval(%<varname>,0) or any other sorts to escape evaluation.

Example:
//var %a = 1 | echo -a %!a = %a

much like you'd quite often do something simple like
//echo -a $!ctime = $ctime

I do get however that this might break some scripts if for some bizarre reason someone uses %! as a variable, but I think that would be slim to none, and would only affect the usage of ! in a variable name from being the very start of the variable. like %a!b should still work, but not %!ab.

Top
#264123 - 30/10/18 02:49 PM Re: block variable evaluation cleaner [Re: Talon]
westor Offline
Hoopy frood

Registered: 27/12/08
Posts: 1506
Loc: Greece
Nice idea +1
_________________________
Need Online mIRC help or an mIRC Scripting Freelancer? -> http://westor.ucoz.com/contact <-

Top
#264124 - 30/10/18 10:44 PM Re: block variable evaluation cleaner [Re: westor]
Raccoon Online
Hoopy frood

Registered: 18/02/03
Posts: 2477
I think, as a backwards-y compatible-y solution... the handling of %!variable would look like this. (As pseudo-coded in mSL for clarity)

Code:
; where $1 is the word being parsed.

if ($left($1,1) == %) {
; this is a variable.

  if ($mid($1,2,1) == !) {
  ; this might be a variable name OR it might be a delayed evaluation.

    if ($var($1,1).local) {
    ; %!variable is a literal local variable name, so let's evaluate it without delay.
    ; (compatibility mode)
      return $eval($1,2)
    }

    elseif ($var($regsubex($1,/^%\K!+/,),1).local) {
    ; %variable (without !'s) is a known local variable, so let's delay evaluation
    ; by removing just one '!' from $1 (eg: from %!!!variable to %!!variable) (new mode)
      return $regsubex($1,/^%\K!/,)
    }

    elseif ($var($1,1).global) {
    ; %!variable is a literal global variable name, so let's evaluate it without
    ; delay. (compatibility mode)
      return $eval($1,2)
    }

    ; else { ; since no known (local or global) variables exist by this name
    ; (eg: %!!!variable) then let's treat it as a delayed evaluation.  (new mode)
    return $regsubex($1,/^%\K!/,)
    ; }
  }

  ; this is just a variable name without '!'.  so try to evaluate it. (as usual)
  return $eval($1,2)

}
_________________________
doiní things a particle can

Top
#264130 - 31/10/18 09:17 PM Re: block variable evaluation cleaner [Re: Raccoon]
Talon Offline
Vogon poet

Registered: 09/12/02
Posts: 191
Loc: Ohio, USA
That's a rather unique idea for backwards compatibility, but really the amount of afftected users would be significantly small, and the solution to anything broken would be a simple find and replace for each loaded script/alias/popup file to find %! and modify it to something else, say %^.

Further info about my topic: "!" has multiple usages already for an escape sequence, why not add it to variables as well?

$identifiers have $!identifier to escape evaluation.
/commands have /!command to escape using a defined alias of that name.

I think variables having %!variable would be a great addition to this already common syntax for escapes.

Figured i'd chime in on some more complex examples to demonstrate why this is useful.

which of these two look cleaner, and easier to follow?

//var %a 0 , %c 0 , %q 0 | scon -at1 var % $+ a % $+ a + 1 , % $+ c % $+ c + $!chan(0) , % $+ q % $+ q + $!query(0) | echo -a $+(%a,/,$scon(0)) active connections, %c Channels and %q Queries.

VS

//var %a 0 , %c 0 , %q 0 | scon -at1 var %!a %!a + 1 , %!c %!c + $!chan(0) , %!q %!q + $!query(0) | echo -a $+(%a,/,$scon(0)) active connections, %c Channels and %q Queries.

Top