TIP #272: STRING AND LIST REVERSAL OPERATIONS =============================================== Version: $Revision: 1.4 $ Author: Donal K. Fellows State: Final Type: Project Tcl-Version: 8.5 Vote: Done Created: Wednesday, 23 August 2006 URL: https://tip.tcl-lang.org272.html Post-History: ------------------------------------------------------------------------- ABSTRACT ========== This TIP proposes adding commands to reverse the order of characters in strings and elements in lists. RATIONALE =========== According to a recent thread on [], there are a number of use cases for reversing strings and lists. While it has always been possible to write Tcl code to do this, it has typically been a fairly inefficient operation, and for some algorithms (admittedly including ones that are benchmarked when comparing Tcl to other languages) this can be the source of a painful slowdown. By putting an efficient implementation in the Tcl core, we will speed up quite a bit of code, more than I originally anticipated it seems; this will make us look better to programmers without much experience with the language too. PROPOSED CHANGE ================= I propose to add two commands, *lreverse* to reverse the order of items in a list, and *string reverse* (a subcommand of *string*) to reverse the order of characters in a string. I do not propose to provide any C-level API for performing these operations. THE LREVERSE COMMAND ---------------------- This shall have the following syntax: *lreverse* /list/ It shall return a list that is the same as the input list but with the elements in reverse order. THE REVERSE SUBCOMMAND OF THE STRING COMMAND ---------------------------------------------- This shall have the following syntax: *string reverse* /string/ It shall return a string that is the same as the input string but with the characters in reverse order. (Note that it shall also return a byte array when the input is a byte array.) COPYRIGHT =========== This document has been placed in the public domain. ------------------------------------------------------------------------- TIP AutoGenerator - written by Donal K. Fellows