Tcl Source Code

Ticket Change Details
Login
Overview

Artifact ID: af2f9a7cd3c91927555186d47d2f24771608170d
Ticket: 0d2bcd9544735adea2d2c3aabd5f0d1e222cb4fc
"lgroup" to regroup a list
User & Date: anonymous 2014-01-12 00:21:31
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/plain"
  4. comment changed to:
    ~ Prototype
    
    lgroup listIn lengthOfSublist ?stepForward?
    
    stepForward defaults to $lengthOfSublist
    
    ~ Example
    
    set l {a b c d e f g h}
    lgroup $l 4 # {a b c d} {e f g h}
    lgroup $l 3 # {a b c} {d e f} {g h}
    lgroup $l 1 # a b c d e f g h
    lgroup $l -1 # error
    lgroup $l 3 2 # {a b c} {c d e} {e f g} {g h}
    lgroup $l 2 3 # {a b} {d e} {g h}
    
    ~ Usefulness
    
    This can be used to rearrange results returned by SQLite3.
    
    ~ Incomplete implementation
    
    Since I just use it to process what SQLite3 returns, I have ignored the "stepForward". I think rewrite it in C will speed it up. I didn't check whether $lengthOfSublist equals to zero.
    
    proc lgroup {listIn lengthOfSublist} {
    	set i 0
    	foreach it $listIn {
    		lappend tmp $it
    		if {[llength $tmp] == $lengthOfSublist} {
    			lappend result $tmp
    			set tmp {}
    		}
    		incr i
    	}
    	if {[expr [llength $listIn] % $lengthOfSublist] != 0} {
    		lappend result $tmp
    	}
    	return $result
    }
    
  5. is_private changed to: "0"
  6. login: "anonymous"
  7. priority changed to: "5 Medium"
  8. private_contact changed to: "c1589a2fa4fc7951c4aba10439d3b95af55c3a63"
  9. resolution changed to: "None"
  10. severity changed to: "Minor"
  11. status changed to: "Open"
  12. submitter changed to: "anonymous"
  13. subsystem changed to: "- New Builtin Commands"
  14. title changed to: ""lgroup" to regroup a list"
  15. type changed to: "RFE"