User Tools

Site Tools


fe

Synopsis:

fe (<list>) <variable> [<variable> …] { <actions> }
fe <source_variable> <variable> [<variable> …] { <actions> }

Description:

Form 1:

FE is one of several loop types available in ircII-EPIC. This loop takes a list of items, and for each one, it performs the specified action.

It may act on more than one item at a time. The list may be a plain text list, a variable, a function, or any combination. As with aliases and other control structures, the braces surrounding the action may appear anywhere. List items are whitespace-delimited. Extended words (those with spaces in them) are honored when they are surrounded in double quotes (“).

For instance, FE might be used to loop through a list of nicknames that the user wishes to invite to a channel (or kick from it!).

Any looping mechanism can run through a list one by one. The real power of FE is its ability to act on multiple list items at once. One could perform an action on 3 at a time, for instance, such as setting a +o channel mode on other users. Other loops, such as FOR, can do this as well, but FE offers a more elegant solution.

Form 2:

The second form of fe allows you to rewrite a control variable that contains a word list. The initial value of the control variable is used as the word list (as in the first form) and after each iteration of the loop, all of the loop variables are appended together to build up a new value for the variable. The control variable is assigned a new value after the conclusion of the final iteration of the loop.

This form might have been named MAP after perls map function but the MAP is already used for something else. It is functionally equivalent to this snippet of code:

    fe ($targetvar) foo {
       ...
       push tempvar $foo
    }
    @ targetvar = tempvar
    @ tempvar = []

BREAKing out of a loop will cause the original list to be truncated _after_ the current set of variables have been written. That is, the break occurs after the push in the above code.

Examples:

A simple mode +o script to cluster mode changes 3 at a time:

    fe ( $friends ) xx yy zz {
       if ( zz ) {
          mode #blah +ooo $xx $yy $zz
       } {
          if ( yy ) {
             mode #blah +oo $xx $yy
          } {
             mode +o $xx
          }
       }
    }

A script to check for upper-case letters in a line of input:

    @ caps = 0
    fec ( $* ) xx {
       if ( ascii($xx) >= 65 || ascii($xx) <= 90 ) {
          @ caps++
       }
    }
    echo *** Found $caps upper-case letters

A script to square all numbers (words) in the $list variable:

    fe list foo {
       @ foo = foo * foo
    }

Aliases:

FEC works the same as FE, except it loops through each character in the list, not each word. Whitespace is only valid if it is between two other non-whitespace characters. Whitespace that follows the opening parenthesis, and that leads up to the closing one, is ignored.

Other Notes:

The loop doesn't necessarily have to have an action inside the curly braces. It doesn't make much sense to omit it, though. Since 01/22/97, FE and FEC use local variables instead of global.

fe.txt · Last modified: 2007/07/10 21:12 (external edit)