Re: Tcl Switch case



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.
.



Relevant Pages

  • Re: Fails to boot after buildworld
    ... > I don't know if this is a bug somewhere in the source but my ... # CFLAGS controls the compiler settings used when compiling C code. ... # Note that optimization settings other than -O and -O2 are not recommended ... If you are not the intended recipient, ...
    (freebsd-questions)
  • Re: Fails to boot after buildworld
    ... > I don't know if this is a bug somewhere in the source but my ... # CFLAGS controls the compiler settings used when compiling C code. ... # Note that optimization settings other than -O and -O2 are not recommended ... If you are not the intended recipient, ...
    (freebsd-stable)
  • Re: Replacement for MS STL?
    ... Here's one of the STL bugs things I found. ... compiling most of my program "Release", for needed speed, while compiling ... Because the switch triggers different, incompatible, memory layouts ... Then it's not a bug. ...
    (microsoft.public.vc.stl)
  • Re: clock scan 8.4/8.5 incompatibility?
    ... Bug doesn't occurs when compiling with recent MSVC, but happens when Tcl is built with MingW and "older" MSVC compilers. ... The key point is that "Posix specs says nothing about how localtime() must handle negative epoch", so generated code vary from one compiler to another. ... localtime failed (clock value may be too large/small to represent) ...
    (comp.lang.tcl)
  • Re: Problems compiling in Platform directory; in Public it works
    ... After editing my files I can compile in the Public directory (I ... but when compiling in ... illegal for switch / O ...
    (microsoft.public.windowsce.embedded)