mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-04-27 07:33:57 +00:00
[tcl/en] Fix #2569 and also fit to 79 columns width
This commit is contained in:
parent
ce00d724a1
commit
13369ee56c
@ -57,9 +57,9 @@ lighter that that of Lisp, just gets out of the way.
|
|||||||
```tcl
|
```tcl
|
||||||
#! /bin/env tclsh
|
#! /bin/env tclsh
|
||||||
|
|
||||||
################################################################################
|
###############################################################################
|
||||||
## 1. Guidelines
|
## 1. Guidelines
|
||||||
################################################################################
|
###############################################################################
|
||||||
|
|
||||||
# Tcl is not Bash or C! This needs to be said because standard shell quoting
|
# Tcl is not Bash or C! This needs to be said because standard shell quoting
|
||||||
# habits almost work in Tcl and it is common for people to pick up Tcl and try
|
# habits almost work in Tcl and it is common for people to pick up Tcl and try
|
||||||
@ -72,9 +72,9 @@ lighter that that of Lisp, just gets out of the way.
|
|||||||
# are formatted as lists.
|
# are formatted as lists.
|
||||||
|
|
||||||
|
|
||||||
################################################################################
|
###############################################################################
|
||||||
## 2. Syntax
|
## 2. Syntax
|
||||||
################################################################################
|
###############################################################################
|
||||||
|
|
||||||
# Every line is a command. The first word is the name of the command, and
|
# Every line is a command. The first word is the name of the command, and
|
||||||
# subsequent words are arguments to the command. Words are delimited by
|
# subsequent words are arguments to the command. Words are delimited by
|
||||||
@ -151,6 +151,8 @@ set greeting "Hello, [set {first name}]"
|
|||||||
|
|
||||||
# To promote the words within a word to individual words of the current
|
# To promote the words within a word to individual words of the current
|
||||||
# command, use the expansion operator, "{*}".
|
# command, use the expansion operator, "{*}".
|
||||||
|
```
|
||||||
|
```tcl
|
||||||
set {*}{name Neo}
|
set {*}{name Neo}
|
||||||
|
|
||||||
# is equivalent to
|
# is equivalent to
|
||||||
@ -171,14 +173,15 @@ namespace eval people {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#The full name of a variable includes its enclosing namespace(s), delimited by two colons:
|
# The full name of a variable includes its enclosing namespace(s), delimited by
|
||||||
|
# two colons:
|
||||||
set greeting "Hello $people::person1::name"
|
set greeting "Hello $people::person1::name"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
################################################################################
|
###############################################################################
|
||||||
## 3. A Few Notes
|
## 3. A Few Notes
|
||||||
################################################################################
|
###############################################################################
|
||||||
|
|
||||||
# All other functionality is implemented via commands. From this point on,
|
# All other functionality is implemented via commands. From this point on,
|
||||||
# there is no new syntax. Everything else there is to learn about Tcl is about
|
# there is no new syntax. Everything else there is to learn about Tcl is about
|
||||||
@ -192,10 +195,11 @@ set greeting "Hello $people::person1::name"
|
|||||||
namespace delete ::
|
namespace delete ::
|
||||||
|
|
||||||
|
|
||||||
# Because of name resolution behaviour, it's safer to use the "variable" command to
|
# Because of name resolution behaviour, it's safer to use the "variable"
|
||||||
# declare or to assign a value to a namespace. If a variable called "name" already
|
# command to declare or to assign a value to a namespace. If a variable called
|
||||||
# exists in the global namespace, using "set" here will assign a value to the global variable
|
# "name" already exists in the global namespace, using "set" here will assign
|
||||||
# instead of creating a new variable in the local namespace.
|
# a value to the global variable instead of creating a new variable in the
|
||||||
|
# local namespace.
|
||||||
namespace eval people {
|
namespace eval people {
|
||||||
namespace eval person1 {
|
namespace eval person1 {
|
||||||
variable name Neo
|
variable name Neo
|
||||||
@ -208,9 +212,9 @@ set people::person1::name Neo
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
################################################################################
|
###############################################################################
|
||||||
## 4. Commands
|
## 4. Commands
|
||||||
################################################################################
|
###############################################################################
|
||||||
|
|
||||||
# Math can be done with the "expr" command.
|
# Math can be done with the "expr" command.
|
||||||
set a 3
|
set a 3
|
||||||
@ -294,7 +298,8 @@ while {$i < 10} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# A list is a specially-formatted string. In the simple case, whitespace is sufficient to delimit values
|
# A list is a specially-formatted string. In the simple case, whitespace is
|
||||||
|
# sufficient to delimit values
|
||||||
set amounts 10\ 33\ 18
|
set amounts 10\ 33\ 18
|
||||||
set amount [lindex $amounts 1]
|
set amount [lindex $amounts 1]
|
||||||
|
|
||||||
@ -406,7 +411,7 @@ proc set_double {varname value} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#get rid of the built-in "while" command.
|
# Get rid of the built-in "while" command.
|
||||||
rename ::while {}
|
rename ::while {}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user