Re: Why don't variables work in switch patterns?
- From: Bruce Hartweg <bruce-news@xxxxxxxxxx>
- Date: Sun, 12 Nov 2006 21:25:25 GMT
Ralf Fassel wrote:
* Bruce <news@xxxxxxxxxxx>
| to parser - that outer word is quoted with {} so the whole thing is
| passed as is to the switch statement - which doesn't do any extra
| substitutions on the pieces.
The confusion might come from the fact that you _can_ use variables
inside the actions, but not in the patterns, if the {} form is used.
Eg.
switch -- $value {
foo {
# can use variables here, but not in the pattern line directly above
puts "value is $value"
}
}
But that is clearly stated in the man pages. In this case the interpreter
does NOT substitute in either the pattern or bodies, they are passed literally
to the switch command which does t he following:
The switch command matches its string argument against each of the pattern arguments in order. As soon as it finds a pattern that matches string it evaluates the following body argument by passing it recursively to the Tcl interpreter and returns the result of that evaluation.
(quoted from http://www.tcl.tk/man/tcl8.4/TclCmd/switch.htm)
so the is no magic goping on - initially NO substitution occurs, then is a pattern
is matched the body associated is passed again to the interpreter - this is when
the variables are/commands are substituted.
Bruce
.
- Follow-Ups:
- Re: Why don't variables work in switch patterns?
- From: Ralf Fassel
- Re: Why don't variables work in switch patterns?
- References:
- Why don't variables work in switch patterns?
- From: Todd A. Jacobs
- Re: Why don't variables work in switch patterns?
- From: Robert Heller
- Re: Why don't variables work in switch patterns?
- From: Bruce
- Re: Why don't variables work in switch patterns?
- From: Ralf Fassel
- Why don't variables work in switch patterns?
- Prev by Date: Re: How to use the Google SOAP API
- Next by Date: Simple regular expressions on a list of symbols instead of a string?
- Previous by thread: Re: Why don't variables work in switch patterns?
- Next by thread: Re: Why don't variables work in switch patterns?
- Index(es):
Relevant Pages
|
|