TIP 289: Revision of [lrepeat] Argument Order

Login
Author:         Peter Spjuth <[email protected]>
Author:          <[email protected]>
State:          Rejected
Type:           Project
Vote:           Done
Created:        26-Oct-2006
Post-History:   
Keywords:       Tcl
Tcl-Version:    8.5

Abstract

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

Rationale

In [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.

Specification

Change lrepeat's argument order to:

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

Examples:

 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]

Discussion:

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.

Copyright

This document has been placed in the public domain.