TIP #289: Revision of [lrepeat] Argument Order

Title:Revision of [lrepeat] Argument Order
Version:$Revision: 1.5 $
Authors: Peter Spjuth <peter dot spjuth at space dot se>
dgp at users dot sf dot net
Created:Thursday, 26 October 2006


This TIP proposes to alter the argument order of lrepeat to be similar to string repeat.


In TIP #136, lrepeat is defined as:

lrepeat number element1 ?element2? ?element3? ...

whereas the old string repeat command is:

string repeat string number

This difference between similar commands is bound to cause confusion. Consistency is good.


Change lrepeat's argument order to:

lrepeat element1 ?element2? ?element3? ... number


 lrepeat 0 100                - returns list of 100 zeros
 lrepeat [lrepeat 0 100] 100  - returns 100x100 matrix (list of lists) of zeros
 lrepeat a b c 3              - returns nine-element list {a b c a b c a b c}
 lrepeat a b c 1              - identical to [list a b c]


DGP: The main feature that appears to get lost in this change is the ability to redirect aliases or subcommands of ensembles to lrepeat calls with the number of repetitions already filled in.

PS: On the other hand, you get the ability to redirect aliases or subcommands of ensembles to lrepeat calls with the elements already filled in.

DGP: I skimmed the old TIP 136 messages in the TCLCORE archives. One thing to note is that the existing lrepeat syntax in 8.5a5 was chosen in part to be consistent with the existing struct::list repeat syntax in the struct::list package.

DGP: I think it's fair to say that given a complete "do-over" more of us would opt to change string repeat to agree with lrepeat and struct::list repeat than the other way around.


This document has been placed in the public domain.

Powered by Tcl[Index] [History] [HTML Format] [Source Format] [LaTeX Format] [Text Format] [XML Format] [*roff Format (experimental)] [RTF Format (experimental)]

TIP AutoGenerator - written by Donal K. Fellows