~ubuntu-branches/ubuntu/raring/tcl8.5/raring

« back to all changes in this revision

Viewing changes to doc/set.n

  • Committer: Bazaar Package Importer
  • Author(s): Sergei Golovan
  • Date: 2007-10-26 22:04:32 UTC
  • Revision ID: james.westby@ubuntu.com-20071026220432-57je4z35i4ll6uit
Tags: upstream-0.b2
ImportĀ upstreamĀ versionĀ 0.b2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
'\"
 
2
'\" Copyright (c) 1993 The Regents of the University of California.
 
3
'\" Copyright (c) 1994-1996 Sun Microsystems, Inc.
 
4
'\"
 
5
'\" See the file "license.terms" for information on usage and redistribution
 
6
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 
7
'\" 
 
8
'\" RCS: @(#) $Id: set.n,v 1.7 2006/08/09 10:06:28 dkf Exp $
 
9
'\" 
 
10
.so man.macros
 
11
.TH set n "" Tcl "Tcl Built-In Commands"
 
12
.BS
 
13
'\" Note:  do not modify the .SH NAME line immediately below!
 
14
.SH NAME
 
15
set \- Read and write variables
 
16
.SH SYNOPSIS
 
17
\fBset \fIvarName \fR?\fIvalue\fR?
 
18
.BE
 
19
 
 
20
.SH DESCRIPTION
 
21
.PP
 
22
Returns the value of variable \fIvarName\fR.
 
23
If \fIvalue\fR is specified, then set
 
24
the value of \fIvarName\fR to \fIvalue\fR, creating a new variable
 
25
if one doesn't already exist, and return its value.
 
26
If \fIvarName\fR contains an open parenthesis and ends with a
 
27
close parenthesis, then it refers to an array element:  the characters
 
28
before the first open parenthesis are the name of the array,
 
29
and the characters between the parentheses are the index within the array.
 
30
Otherwise \fIvarName\fR refers to a scalar variable.
 
31
.PP
 
32
If \fIvarName\fR includes namespace qualifiers
 
33
(in the array name if it refers to an array element), or if \fIvarName\fR
 
34
is unqualified (does not include the names of any containing namespaces)
 
35
but no procedure is active, 
 
36
\fIvarName\fR refers to a namespace variable
 
37
resolved according to the rules described under \fBNAME RESOLUTION\fR in
 
38
the \fBnamespace\fR manual page.
 
39
.PP
 
40
If a procedure is active and \fIvarName\fR is unqualified, then
 
41
\fIvarName\fR refers to a parameter or local variable of the procedure,
 
42
unless \fIvarName\fR was declared to resolve differently through one of the 
 
43
\fBglobal\fR, \fBvariable\fR or \fBupvar\fR commands.
 
44
.SH EXAMPLES
 
45
Store a random number in the variable \fIr\fR:
 
46
.CS
 
47
\fBset\fR r [expr {rand()}]
 
48
.CE
 
49
.PP
 
50
Store a short message in an array element:
 
51
.CS
 
52
\fBset\fR anAry(msg) "Hello, World!"
 
53
.CE
 
54
.PP
 
55
Store a short message in an array element specified by a variable:
 
56
.CS
 
57
\fBset\fR elemName "msg"
 
58
\fBset\fR anAry($elemName) "Hello, World!"
 
59
.CE
 
60
.PP
 
61
Copy a value into the variable \fIout\fR from a variable whose name is
 
62
stored in the \fIvbl\fR (note that it is often easier to use arrays in
 
63
practice instead of doing double-dereferencing):
 
64
.CS
 
65
\fBset\fR in0 "small random"
 
66
\fBset\fR in1 "large random"
 
67
\fBset\fR vbl in[expr {rand() >= 0.5}]
 
68
\fBset\fR out [\fBset\fR $vbl]
 
69
.CE
 
70
 
 
71
.SH "SEE ALSO"
 
72
expr(n), global(n), namespace(n), proc(n), trace(n), unset(n), upvar(n), variable(n)
 
73
 
 
74
.SH KEYWORDS
 
75
read, write, variable