Perhaps I'm just having a bout of Perl envy, but I keep wanting to implement an lmap and lgrep set of procs that do map and grep on lists. Sample usage:
% set l [list a b c d] a b c d % lmap l { format %s%s $_ $_ } aa bb cc dd % lgrep l { string match *d* $_ } d
These are easy enough to implement in Tcl:
proc lmap {listName expr} { upvar $listName list foreach _ $list { lappend newList [eval $expr] } return $newList } proc lgrep {listName expr} { upvar $listName list foreach _ $list { if [eval $expr] { lappend newList $_ } } return $newList }
Does anyone else wish these were part of standard Tcl? Would someone want to write up the TIP to try and get this in?
-- Dossy 13aug2003
[ Category Suggestions ]