Version 6 of zip

Updated 2005-09-22 00:08:01

[...]

Steve Cassidy: "Trf lets you zip up a bit of data but doesn't provide the machinery to zip directories or files. mkZipLib [L1 ] provides such an interface as does zvfs [L2 ]. More up to date is the zipvfs package which is part of tclvfs but that doesn't seem to be working cleanly yet and requires tcl8.4 features."

http://www.equi4.com/critlib/zipper.README http://www.equi4.com/critlib/zlib.README

See also Using a zip file as a Tcl Module.


NEM zip is also the name of another functional programming classic. You can think of it as a function that takes a bunch of "columns" (think relational) and returns a list of "rows":

 proc zip {cola colb} {
   set ret [list]
   foreach a $cola b $colb { lappend ret [list $a $b] }
   return $ret
 }
 zip {1 2 3} {a b c} ;# returns {{1 a} {2 b} {3 c}}

You can generalise zip to zipWith which applies an arbitrary function on each pair of values from the columns:

 proc apply {func args} { uplevel #0 $func $args }
 proc zipWith {f cola colb} {
   set ret [list]
   foreach a $cola b $colb { lappend ret [apply $f $a $b] }
   return $ret
 }
 interp alias {} zip {} zipWith list

You could further generalise the function to take an arbitrary number of columns. I'll leave that, and the reverse unzip operation as exercises. See also fold, filter, iterators and map.


Category Compression