liststat.tcl

Go to the documentation of this file.
00001 /*  liststat.tcl --*/
00002 /* */
00003 /*     Set of operations on lists, meant for the statistics package*/
00004 /* */
00005 /*  version 0.1: initial implementation, january 2003*/
00006 
00007 namespace ::math::statistics {}
00008 
00009 /*  filter --*/
00010 /*     Filter a list based on whether an expression is true for*/
00011 /*     an element or not*/
00012 /* */
00013 /*  Arguments:*/
00014 /*     varname        Name of the variable that represents the data in the*/
00015 /*                    expression*/
00016 /*     data           List to be filtered*/
00017 /*     expression     (Logical) expression that is to be evaluated*/
00018 /* */
00019 /*  Result:*/
00020 /*     List of those elements for which the expression is true*/
00021 /*  TODO:*/
00022 /*     Substitute local variables in caller*/
00023 /* */
00024 ret  ::math::statistics::filter ( type varname , type data , type expression ) {
00025    upvar $varname _x_
00026    set result {}
00027    set _x_ \$_x_
00028    set expression [uplevel subst -nocommands [list $expression]]
00029    foreach _x_ $data {
00030       # FRINK: nocheck
00031       if $expression {
00032 
00033          lappend result $_x_
00034       }
00035    }
00036    return $result
00037 }
00038 
00039 /*  map --*/
00040 /*     Map the elements of a list according to an expression*/
00041 /* */
00042 /*  Arguments:*/
00043 /*     varname        Name of the variable that represents the data in the*/
00044 /*                    expression*/
00045 /*     data           List whose elements must be transformed (mapped)*/
00046 /*     expression     Expression that is evaluated with $varname an*/
00047 /*                    element in the list*/
00048 /* */
00049 /*  Result:*/
00050 /*     List of transformed elements*/
00051 /* */
00052 ret  ::math::statistics::map ( type varname , type data , type expression ) {
00053    upvar $varname _x_
00054    set result {}
00055    set _x_ \$_x_
00056    set expression [uplevel subst -nocommands [list $expression]]
00057    foreach _x_ $data {
00058       # FRINK: nocheck
00059       lappend result [expr $expression]
00060    }
00061    return $result
00062 }
00063 
00064 /*  samplescount --*/
00065 /*     Count the elements in each sublist and return a list of counts*/
00066 /* */
00067 /*  Arguments:*/
00068 /*     varname        Name of the variable that represents the data in the*/
00069 /*                    expression*/
00070 /*     list           List of lists*/
00071 /*     expression     Expression in that is evaluated with $varname an*/
00072 /*                    element in the sublist (defaults to "true")*/
00073 /* */
00074 /*  Result:*/
00075 /*     List of transformed elements*/
00076 /* */
00077 ret  ::math::statistics::samplescount ( type varname , type list , optional expression =1 ) {
00078    upvar $varname _x_
00079    set result {}
00080    set _x_ \$_x_
00081    set expression [uplevel subst -nocommands [list $expression]]
00082    foreach data $list {
00083       set number 0
00084       foreach _x_ $data {
00085          # FRINK: nocheck
00086          if $expression {
00087             incr number
00088          }
00089       }
00090       lappend result $number
00091    }
00092    return $result
00093 }
00094 
00095 /*  End of list procedures*/
00096 

Generated on 21 Sep 2010 for Gui by  doxygen 1.6.1