Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!mis.mcw.edu!tenaglia From: tenaglia@mis.mcw.edu (Chris Tenaglia - 257-8765) Newsgroups: comp.lang.icon Subject: Handy Dandy List Cooker Message-ID: <8911272129.AA22193@uwm.edu> Date: 27 Nov 89 18:06:40 GMT Sender: daemon@ucbvax.BERKELEY.EDU Distribution: inet Organization: The Internet Lines: 58 Dear Icon-Group, Here is another very useful procedure. I call it cook. It takes a list of strings (filenames, usernames, etc,...) and converts them into a list of output lines. It currently assumes that the list is sorted. One can output a list of strings usually by every writes(!elements," ") where elements is a list of strings. But the format is typically like the VMS DIR or DOS DIR/W command. Unix generates a vertically oriented alphabetical list of filenames which is easier to look through. I submit my attempt below. However, my code does not have much of the spirit of icon to it, and many of you may have more elegant (and more efficient) implementations. Please feel free to improve on it. Perhaps even a different approach as a type of sorter? Have fun! The prototype is - procedure cook(lst,cols,width) required : lst is the sorted list of strings to be formatted optional : cols is how many cols are desired (5 is default) optional : width is the output width (80 is default) Yours truly, Chris Tenaglia (System Manager) tenaglia@mis.mcw.edu Medical College of Wisconsin 8701 W. Watertown Plank Rd. Milwaukee, WI 53226 (414)257-8765 ====================================================================== ################################################################## # # # THIS PROCEDURE COOKS A LIST OF STRINGS SO THAT THE LIST COMES # # OUT IN UNIX LS FORMAT RATHER THAN VMS DIR FORMAT # # # ################################################################## procedure cook(lst,cols,width) local limit,size,array,meal,food,i,j,row,column /cols := 5 ; /width := 80 items := *lst ; size := width / cols rows := items / cols + 1 ; limit := rows * cols array := table(" ") ; meal := [] until *lst > limit do put(lst," ") # push for reverse order every column := 1 to cols do every row := 1 to rows do array[row||","||column] := pop(lst) # pull for reverse order every row := 1 to rows do { food := "" every column := 1 to cols do food ||:= left(array[row||","||column],size) put(meal,trim(food)) } return meal end