| 1 | '\" | 
|---|
| 2 | '\" Copyright (c) 1993 The Regents of the University of California. | 
|---|
| 3 | '\" Copyright (c) 1994-1996 Sun Microsystems, Inc. | 
|---|
| 4 | '\" Copyright (c) 2001 Kevin B. Kenny <kennykb@acm.org>.  All rights reserved. | 
|---|
| 5 | '\" | 
|---|
| 6 | '\" See the file "license.terms" for information on usage and redistribution | 
|---|
| 7 | '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. | 
|---|
| 8 | '\"  | 
|---|
| 9 | '\" RCS: @(#) $Id: lrange.n,v 1.17 2008/03/26 09:59:22 dkf Exp $ | 
|---|
| 10 | '\"  | 
|---|
| 11 | .so man.macros | 
|---|
| 12 | .TH lrange n 7.4 Tcl "Tcl Built-In Commands" | 
|---|
| 13 | .BS | 
|---|
| 14 | '\" Note:  do not modify the .SH NAME line immediately below! | 
|---|
| 15 | .SH NAME | 
|---|
| 16 | lrange \- Return one or more adjacent elements from a list | 
|---|
| 17 | .SH SYNOPSIS | 
|---|
| 18 | \fBlrange \fIlist first last\fR | 
|---|
| 19 | .BE | 
|---|
| 20 |  | 
|---|
| 21 | .SH DESCRIPTION | 
|---|
| 22 | .PP | 
|---|
| 23 | \fIList\fR must be a valid Tcl list.  This command will | 
|---|
| 24 | return a new list consisting of elements | 
|---|
| 25 | \fIfirst\fR through \fIlast\fR, inclusive. | 
|---|
| 26 | .VS 8.5 | 
|---|
| 27 | The index values \fIfirst\fR and \fIlast\fR are interpreted | 
|---|
| 28 | the same as index values for the command \fBstring index\fR, | 
|---|
| 29 | supporting simple index arithmetic and indices relative to the | 
|---|
| 30 | end of the list. | 
|---|
| 31 | .VE | 
|---|
| 32 | If \fIfirst\fR is less than zero, it is treated as if it were zero. | 
|---|
| 33 | If \fIlast\fR is greater than or equal to the number of elements | 
|---|
| 34 | in the list, then it is treated as if it were \fBend\fR. | 
|---|
| 35 | If \fIfirst\fR is greater than \fIlast\fR then an empty string | 
|---|
| 36 | is returned. | 
|---|
| 37 | Note: | 
|---|
| 38 | .QW "\fBlrange \fIlist first first\fR" | 
|---|
| 39 | does not always produce the same result as | 
|---|
| 40 | .QW "\fBlindex \fIlist first\fR" | 
|---|
| 41 | (although it often does for simple fields that are not enclosed in | 
|---|
| 42 | braces); it does, however, produce exactly the same results as | 
|---|
| 43 | .QW "\fBlist [lindex \fIlist first\fB]\fR" | 
|---|
| 44 | .SH EXAMPLES | 
|---|
| 45 | Selecting the first two elements: | 
|---|
| 46 | .CS | 
|---|
| 47 | % \fBlrange\fR {a b c d e} 0 1 | 
|---|
| 48 | a b | 
|---|
| 49 | .CE | 
|---|
| 50 | .PP | 
|---|
| 51 | Selecting the last three elements: | 
|---|
| 52 | .CS | 
|---|
| 53 | % \fBlrange\fR {a b c d e} end-2 end | 
|---|
| 54 | c d e | 
|---|
| 55 | .CE | 
|---|
| 56 | .PP | 
|---|
| 57 | Selecting everything except the first and last element: | 
|---|
| 58 | .CS | 
|---|
| 59 | % \fBlrange\fR {a b c d e} 1 end-1 | 
|---|
| 60 | b c d | 
|---|
| 61 | .CE | 
|---|
| 62 | .PP | 
|---|
| 63 | Selecting a single element with \fBlrange\fR is not the same as doing | 
|---|
| 64 | so with \fBlindex\fR: | 
|---|
| 65 | .CS | 
|---|
| 66 | % set var {some {elements to} select} | 
|---|
| 67 | some {elements to} select | 
|---|
| 68 | % lindex $var 1 | 
|---|
| 69 | elements to | 
|---|
| 70 | % \fBlrange\fR $var 1 1 | 
|---|
| 71 | {elements to} | 
|---|
| 72 | .CE | 
|---|
| 73 |  | 
|---|
| 74 | .SH "SEE ALSO" | 
|---|
| 75 | list(n), lappend(n), lindex(n), linsert(n), llength(n), lsearch(n),  | 
|---|
| 76 | lset(n), lreplace(n), lsort(n), | 
|---|
| 77 | .VS 8.5 | 
|---|
| 78 | string(n) | 
|---|
| 79 | .VE | 
|---|
| 80 |  | 
|---|
| 81 | .SH KEYWORDS | 
|---|
| 82 | element, list, range, sublist | 
|---|