Re: Tcl Switch case
- From: "Donal K. Fellows" <donal.k.fellows@xxxxxxxxxxxxxxxx>
- Date: Wed, 20 Feb 2008 10:52:01 +0000
tom.rmadilo wrote:
It appears that more code would benefit from
byte compiling if the '--' argument was respected as an option
termination.
I can't make people write in good style. I can only work to reward those
who do so.
In fact, if this was used as the sole determinant for
byte compiling, only the old two arg 'bug' would fail to be included
in the list of forms which could be byte compiled.
The syntax of [switch] is an awful mess, and the code to compile it is
the most complex part of the bytecode compiler. For the record, it
handles the cases that are "definitely unambiguous" and, after a lot of
thought, I added the two-arg case to that list. I did this on the
grounds that it is far more likely for people to omit options than to
omit the argument being switched upon. It also makes the syntax error
messages much less strange. For example, with Tcl 8.4.16:
% set foo -glob
-glob
% switch $foo {bar {expr 1} default {expr 2}}
wrong # args: should be "switch ?switches? string pattern body ... ?default body?"
% set errorInfo
wrong # args: should be "switch ?switches? string pattern body ... ?default body?"
while executing
"switch $foo {bar {expr 1} default {expr 2}}"
You can't tell me that that example is obvious for newcomers! Indeed, it is particularly bad as it gives no indication that what's happened is that it has misunderstood the first argument, but instead it leads them to use the alternate, harder-to-use [switch] syntax while *still* having a problem.
(Aside: Funnily enough, the first version of the [switch] compiler
didn't support the most common form of switch syntax at all due to the
complexity of token handling. Most of the real complexity stems from two
things; handling the pattern/body list form, and generating an efficient
scheme for exact matching against literals. The two-arg form is, by
comparison, an afterthought.)
Maybe the current maintainers should reflect on the Ancient wisdom of
the Ancients.
Remember, sometimes it's not ancient wisdom but rather ancient mistakes.
Why would some old fart use an option '--' if not to aid
in parsing the meaning of a command? I know that there is a theory
that commands key off of the number of arguments, but this is just a
theory. Another theory, one enshrined in Tcl, is that arguments are
processed _in order_. This is the concept of parsing. Parsing is made
very easy if you 'parse', and that means to process an input from
first char to last, with no backtracking.
This has never reflected reality. In particular, Tcl commands have
*always* known how many arguments they have and have made decisions
based on this before looking at the content of the arguments.
Wait, what is the bug? Not sure what I can report as a bug given that
'what is a bug' has been redefined.
There are many general definitions of a bug, including:
* variation between specification and implementation, and
* ambiguity of specification.
But in general the "bug-ness" of something is determined by whether
multiple people agree that it is a bug. If *you* think something is a
bug, report it and see if others agree.
That said, this is a storm in a teacup. A mighty mountain range from a
small molehill. If you were a paranoid programmer before, you wouldn't
have been using the two-arg case anyway and you would be unaffected by
the change. If you weren't, you will now be better served by there now
being one less landmine to stumble over.
Donal.
.
- 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: WL
- Re: Tcl Switch case
- From: Bryan Oakley
- Re: Tcl Switch case
- From: Donal K. Fellows
- Re: Tcl Switch case
- From: Bryan Oakley
- Re: Tcl Switch case
- From: Donal K. Fellows
- Re: Tcl Switch case
- From: Bryan Oakley
- Re: Tcl Switch case
- From: tom.rmadilo
- Re: Tcl Switch case
- From: Mark Janssen
- Re: Tcl Switch case
- From: tom.rmadilo
- Re: Tcl Switch case
- From: Andreas Leitgeb
- Re: Tcl Switch case
- From: tom.rmadilo
- Tcl Switch case
- Prev by Date: Re: Tcl Switch case
- Next by Date: Re: Tcl Switch case
- Previous by thread: Re: Tcl Switch case
- Next by thread: Re: Tcl Switch case
- Index(es):
Relevant Pages
|