Re: Tcl Switch case
- From: Mark Janssen <mpc.janssen@xxxxxxxxx>
- Date: Tue, 19 Feb 2008 02:36:39 -0800 (PST)
On 19 feb, 10:02, "MartinLemburg@Siemens-PLM"
<martin.lemburg.siemens-...@xxxxxxx> wrote:
Hi Andreas,
while willing to agree, that this 8.5(.x) change (it works in 8.5.0,
too) equalizes the behaviour of such commands like lsearch, switch,
etc.:
% lsearch -hello *hello
0
% switch -hello {-hello {expr {0}}}
0
But I'm not willing to accept it as feature if syntactical elements
are handled like you showed:
% switch -- {-- {expr {0}}}
0
This is definitely (IMHO) an error, because "--" signals the end of
the options and that the next argument is the string to be used with
the switch cases.
It should behave like e.g. ...
% glob --; # could have returned an empty list
wrong # args: should be "glob ?switches? name ?name ...?"
% regexp -- ----; # could have return 1
wrong # args: should be "regexp ?switches? exp string ?matchVar? ?
subMatchVar subMatchVar ...?"
% regsub -- ---- !; # could have returned "!!"
wrong # args: should be "regsub ?switches? exp string subSpec ?
varName?"
So - no matter how far switch is nearer to e.g. lsearch in its syntax,
it is now much far away from the syntax of "--" accepting commands.
Best regards,
Martin
P.S.: I never understood, why such syntactical differences are between
e.g. lsort and e.g. switch. The first accepts any "-\w+" pattern as
data, if it is no valid option, the last throws an error if an "-\w+"
argument is not a valid option. What's about equalizing option
accepting commands?
On 18 Feb., 21:30, Andreas Leitgeb <a...@xxxxxxxxxxxxxxxxxxxxxxxx>
wrote:
Donald Arseneau <a...@xxxxxxxxx> wrote:
On Feb 18, 7:43 am, Mark Janssen <mpc.jans...@xxxxxxxxx> wrote:
Or use the stable Tcl 8.5.1. 8.5.1 recognizes that with [switch $aWHAT!?!? That breaks Tcl's parser rules.
$body], $a cannot be a flag so it will not try to interpret it as one..
nothing actually does.
The $a must be substituted
before the switch command has any effect -- it (switch) can only see
the resulting text that came out of $a.
What you say is true, but who spoke against it?
switch -- {-- {puts ok}}
Of course also prints "ok" to stdout (with 8.5.1 and up), so no
discrimination between $,[] and constant values is happening.
It's the number of args, that prevents "switch $a $body" from
taking $a for an option, not whether they're constant or not.
I certainly agree that the option handling of Tcl commands is a bit
inconsistent between commands. One of the things I would like to see
addressed in Tcl9 is making option handling in Tcl more uniform and
providing an easier way to add the same handling in your own procs.
I was thinking about using for instance a dict to pass options, but I
am not sure I really like the syntax that would lead to e.g.
lsearch {-inline 1 -all 1} list pattern
all commands would then have the general form:
command ?options? arg1 arg2 arg3 .....
This also has the advantage of removing the need for -- to signify the
end of the options. Determining if any options have been specified
reduces to simple argument counting for all commands.
Mark
.
- References:
- Tcl Switch case
- From: vinayak.mdesai@xxxxxxxxx
- Re: Tcl Switch case
- From: Andreas Leitgeb
- Re: Tcl Switch case
- From: Mark Janssen
- Re: Tcl Switch case
- From: Donald Arseneau
- Re: Tcl Switch case
- From: Andreas Leitgeb
- Re: Tcl Switch case
- From: MartinLemburg@Siemens-PLM
- Tcl Switch case
- Prev by Date: Re: Problems with Expect
- Next by Date: recursive grab current - raise - update
- Previous by thread: Re: Tcl Switch case
- Next by thread: Re: Tcl Switch case
- Index(es):
Relevant Pages
|
|