HomeContentsContents

map

The map expression loops a variable through a list, dictionary, or integer range, evaluating an expression for each iteration. Results from each iteration are collected into a list and returned when the loop is completed. The syntax for map can be either of the following:


        map var in (what_expr) to (iteration_expr)
        map var in [lower_expr .. upper_expr] to (iteration_expr) 
    

Examples:


        map x in ([1, 2, 3]) to (tostr(x))
            => ["1", "2", "3"]

        map x in [5 .. 15] to (x)
            => [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
    
Top

hash

The hash expression loops a variable through a list, dictionary, or integer range, evaluating an expression for each iteration. Results from each iteration must be contained within a two element list. The list is inserted as the key/value pair into a dictionary. After the loop completes, the final dictionary is returned. The syntax for hash can be either of the following:


        hash var in (what_expr) to (interation_expr)
        hash var in [lower_expr .. upper_expr] to (iteration_expr)
    

Examples:


        hash x in ([1, 2, 3]) to ([toobjnum(x), x])
            => #[[$root, 1], [$sys, 2], [$files, 3]]

        hash x in [1 .. 3] to (.random_pair())
            => #[["Dancer", 1], ["Miro", 7], ["$root", 1]]
    

In the above example the method .random_pair() returns a random two element key/value pair.

Top

find

The find expression is used to find the position of something in a list or dictionary. It does this by looping through the given list or dictionary and testing the iteration expression. When the iteration expression evaluates true it stops and returns the given position. The syntax of find is:


        find var in (what_expr) where (iteration_expr)
        find var in [lower_expr .. upper_expr] where (iteration_expr)
    

If the iteration expression never evaluates true, find returns a zero. The following examples assume the variable list is set as:


        ["First line","second line","3rd line"]

        list[find x in (list) where (x.match_regexp("co"))]
            => "second line"

        find x in [1 .. listlen(list)] where (list[x].match_regexp("co"))
            => 2
    
Top

filter

The filter expression is used to selectively pull elements from a list or dictionary. It loops through the given list or dictionary and adds each element to a new list if the iteration expression tests true. The final list is returned after filter finishes looping. The syntax of filter is:


        filter var in (what_expr) where (iteration_expr)
        filter var in [lower_expr .. upper_expr] where (iteration_expr)
    

The following examples assume the variable list is set as:


        ["First line", "second line", "3rd line"]

        filter x in (list) where (x.match_regexp("co"))
           => ["second line"]

        filter x in [1 .. list.length()] where (list[x].match_regexp("co"));
           => [2]
    
Top

Contents Back Functions

Valid XHTML 1.0 Strict