Feather Container


loop command

This is a generic command for iterating over containers.

loop <varList> <container> <script>

The varList may contain either one or two variable names. If only one is specified it iterates over the values in the containers, if two are specified the first one iterates over the keys and the second one iterates over the values.

The container may be any object which supports the container interface. An attempt will be made to convert it to a list if it does not natively support the container interface.

e.g.

        % loop v [list a b c d] {
            puts $v
        }
        a
        b
        c
        d

        % loop {i v} [list a b c d] {
            puts "$i $v"
        }
        0 a
        1 b
        2 c
        3 d

        % loop v [map create {alpha a baker b}] {
            puts $v
        }
        a
        b

        % loop {i v} [map create {alpha a baker b}] {
            puts "$i $v"
        }
        alpha a
        baker b

accessor commands

getx <container> <key> ?<key> ...?
Returns the value associated with the key in the specified container. If more than one key is specified then each subsequent key is looked up in the container returned from the previous search.
        % set a [list [vector create 1 2 3]]
        {<feather::vector 0x200438a8>}
        % getx $a 0
        <feather::vector 0x200438a8>
        % getx $a 0 1
        2
setx <container> <key> ?<key> ...? <value>
Sets the value associated with the key in the container. The multi-key format is shorthand.
        setx <container> <key1> <key2> <key3> <key4> <value> 
                is equivalent to 
        setx [getx <container> <key1> <key2> <key3>] <key4> <value>

        % set a [list [vector create 1 2 3]]
        {<feather::vector 0x200438a8>}
        % setx $a 0 99
        lists are read-only
        % setx $a 0 1 99
        % vector contents [getx $a 0]
        1 99 3

count command

count <container>
Returns the number of elements in the container.