How about this code:
switch(foo.bar().baz().fred().wilma().barney())
{
case 0..12:
blah
break;
default:
blah2
break;
}
It would be cool to have a keyword/automatic variable that contains the
value that was put into th switch() clause so that I don't have to call
the long string of functions again (or to have a temporary variable).
--
The Villagers are Online! villagersonline.com
.[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ]
.[ (a version.of(English).(precise.more)) is(possible) ]
?[ you want.to(help(develop(it))) ]

How about this code:
switch(foo.bar().baz().fred().wilma().barney())
{
case 0..12:
blah
break;
default:
blah2
break;
}
It would be cool to have a keyword/automatic variable that contains the
value that was put into th switch() clause so that I don't have to call
the long string of functions again (or to have a temporary variable).

Sorta BASIC? Well, since current object is "this", we could call it
"it". =) It would also be nice to have the same feature in with():
with (foo.bar.baz)
{
if (!okay)
kill(it);
}
// -- OR --
switch (foo.bar.baz.okay)
{
case 1:
kill(it);
}
Something I wanted to see in some language for a long time already...

How about this code:
switch(foo.bar().baz().fred().wilma().barney())
{
case 0..12:
blah
break;
default:
blah2
break;
}
It would be cool to have a keyword/automatic variable that contains the
value that was put into th switch() clause so that I don't have to call
the long string of functions again (or to have a temporary variable).

Sorta BASIC? Well, since current object is "this", we could call it
"it". =) It would also be nice to have the same feature in with():
with (foo.bar.baz)
{
if (!okay)
kill(it);
}
// -- OR --
switch (foo.bar.baz.okay)
{
case 1:
kill(it);
}
Something I wanted to see in some language for a long time already...

And how do you get the value of and outer switch from cases of an inner
(nested) switch ? Local(s) variable(s) is(are) back ?
Local declaration (like in for (...) in C++) should be ok:
switch(int it1 = foo.bar().baz().fred().wilma().barney())
{
case 0..12:
switch (int it2 = foo.bar().baz().fred().wilma().casey())
{
case 23..41:
do(it1 + it2);
...
}
// it2 out of scope here
...
}
// it1 out of scope here
By the way, I'd like something like:
var v = expr;
declaration where "= expr" is required and v type is expr static type. This
is not an untyped variable, only an automatic typeof(expr). Sometimes, it
realy bugs me to have to search for the spelling of a type or to have to do
plenty of types copy/paste.
"Pavel Minayev" wrote:

How about this code:
switch(foo.bar().baz().fred().wilma().barney())
{
case 0..12:
blah
break;
default:
blah2
break;
}
It would be cool to have a keyword/automatic variable that contains the
value that was put into th switch() clause so that I don't have to call
the long string of functions again (or to have a temporary variable).

Sorta BASIC? Well, since current object is "this", we could call it
"it". =) It would also be nice to have the same feature in with():
with (foo.bar.baz)
{
if (!okay)
kill(it);
}
// -- OR --
switch (foo.bar.baz.okay)
{
case 1:
kill(it);
}
Something I wanted to see in some language for a long time already...

How about this code:
switch(foo.bar().baz().fred().wilma().barney())
{
case 0..12:
blah
break;
default:
blah2
break;
}
It would be cool to have a keyword/automatic variable that contains

the

value that was put into th switch() clause so that I don't have to

call

the long string of functions again (or to have a temporary variable).

Sorta BASIC? Well, since current object is "this", we could call it
"it". =) It would also be nice to have the same feature in with():
with (foo.bar.baz)
{
if (!okay)
kill(it);
}
// -- OR --
switch (foo.bar.baz.okay)
{
case 1:
kill(it);
}
Something I wanted to see in some language for a long time already...

How about this code:
switch(foo.bar().baz().fred().wilma().barney())
{
case 0..12:
blah
break;
default:
blah2
break;
}
It would be cool to have a keyword/automatic variable that contains the
value that was put into th switch() clause so that I don't have to call
the long string of functions again (or to have a temporary variable).

Sorta BASIC? Well, since current object is "this", we could call it
"it". =) It would also be nice to have the same feature in with():

snip

Something I wanted to see in some language for a long time already...

The first computer language with pronouns! I love it. :-)
But if we have trouble keeping the antecedents straight in English, I fear
it might be harder in a computer language. :-(
--
- Stephen Fuld
e-mail address disguised to prevent spam

How about this code:
switch(foo.bar().baz().fred().wilma().barney())
{
case 0..12:
blah
break;
default:
blah2
break;
}
It would be cool to have a keyword/automatic variable that contains the
value that was put into th switch() clause so that I don't have to call
the long string of functions again (or to have a temporary variable).
--
The Villagers are Online! villagersonline.com
.[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ]
.[ (a version.of(English).(precise.more)) is(possible) ]
?[ you want.to(help(develop(it))) ]

How about this code:
switch(foo.bar().baz().fred().wilma().barney())
{
case 0..12:
blah
break;
default:
blah2
break;
}
It would be cool to have a keyword/automatic variable that contains the
value that was put into th switch() clause so that I don't have to call
the long string of functions again (or to have a temporary variable).

'cause you have to declare temp outside of switch(), and it will
thus interfere with other switch blocks out there. If only
we could declare variables like in for:
switch (int temp = foo.bar.baz)
But even then, why not let the compiler do it, since it's
rather common?

'cause you have to declare temp outside of switch(), and it will
thus interfere with other switch blocks out there. If only
we could declare variables like in for:
switch (int temp = foo.bar.baz)

sorry as I did not know the type foo returns I ommitted specifying the
variable define (damn nitt pickers :-)) - what I ment was effectively
switch( typeReturnedByFoo temp = foo.bar .... and so on

But even then, why not let the compiler do it, since it's
rather common?

Because that would probably require either another keyword to access.
We could use a variable with local scope to the switch block, or auto
type define on a = ... the first would require a lot of compiler support
and the second can be tricky to implement. So why bother when it is easy
to declare a tempory variable, after all in object oriented programming
procedures (methods) are normally quite short and having a few extra
tempory references should not be an enormous problem.

We could use a variable with local scope to the switch block, or auto
type define on a = ... the first would require a lot of compiler support
and the second can be tricky to implement. So why bother when it is easy
to declare a tempory variable, after all in object oriented programming
procedures (methods) are normally quite short and having a few extra
tempory references should not be an enormous problem.

You mean declaring temporary outside of switch block? Then
why bother declaring counter inside for? I believe that
variables should be as local as possible, so, for the value
of switch expression, it should be local to switch - whatever
way it is done.

You mean declaring temporary outside of switch block? Then
why bother declaring counter inside for?
I believe that variables should be as local as possible, so, for
the value of switch expression, it should be local to switch -
whatever way it is done.

Well so long as I can increase the scope of the variables to that of the
entire procedure I have no problem with allowing variables to be even more
local - I really dislike the way VHDL forces you to use locals to for loops
which dissappear after the loops exits, stopping you reading the final
value. However the D syntax seems to make this senario highly improbable.
I would be quite happy with allowing variables to be scoped within a block,
so long as we do not end up allowing (as some languages do) ...
int x;
switch( int x = foo() ) { ... }
After all I am not writing the compiler.
C 2002/3/28

so long as we do not end up allowing (as some languages do) ...
int x;
switch( int x = foo() ) { ... }

This is exactly how D works. You can have a variable local to block
rather than function, but you cannot have two locals with the same
name at once.
Now if we get that in-place declaration for switch(), I guess
the problem is solved.

BOGGLE...here's a weird idea. What if you could declare a named switch,
kind of like declaring a variable?
int myVar switch(foo.bar().baz().fred().wilma().barney())
{
case 0..12:
DoStuff(myVar); break;
default:
DoOtherStuff(myVar);
}
The scope of the variable would be just the switch block. Or what about
this syntax:
switch(foo.bar().baz().fred().wilma().barney()) as in myVar {...}
Thoughts?
--
The Villagers are Online! villagersonline.com
.[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ]
.[ (a version.of(English).(precise.more)) is(possible) ]
?[ you want.to(help(develop(it))) ]

BOGGLE...here's a weird idea. What if you could declare a named switch,
kind of like declaring a variable?
int myVar switch(foo.bar().baz().fred().wilma().barney())
The scope of the variable would be just the switch block. Or what about
this syntax:
switch(foo.bar().baz().fred().wilma().barney()) as in myVar {...}
Thoughts?

BOGGLE...here's a weird idea. What if you could declare a named switch,
kind of like declaring a variable?
int myVar switch(foo.bar().baz().fred().wilma().barney()) { case
0..12:
DoStuff(myVar); break;
default:
DoOtherStuff(myVar);
}

I thought of an idea like this. The next step would be to say that rather
than doing "continue/goto case 12" you could simply set myVar to 12 and
"continue". If you wanted to break you could do so as normal.
This gives you a kind of state-machine switch loop. Nice and very
powerful but perhaps a bit dangerous:-)
Ben.

This gives you a kind of state-machine switch loop. Nice and very
powerful but perhaps a bit dangerous:-)

Yeah, there's a certain coolness factor to it...but seems like it would be
confusing. Putting a switch inside a while loop would probably be more
readable :)
--
The Villagers are Online! villagersonline.com
.[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ]
.[ (a version.of(English).(precise.more)) is(possible) ]
?[ you want.to(help(develop(it))) ]

The only thing this thread does for me is make me want the old Pascal 'with'
statement. Even that had some flaws. I wasn't aware that D had a with
statement. I should go look that up.
I just can't see why you can't merely do this:
int myVar = foo.bar().baz().fred().wilma().barney();
switch (myVar)
{
case 0..12:
DoStuff(myVar); break;
default:
DoOtherStuff(myVar);
}
I don't see what you're gaining in the below. Also, both the syntaxes below
just look wonky to me.
Some way to declare the variable inside the switch expression ala 'for'
loops would be great. Same with 'while' and 'if', although it's hard to
combine a declaration with a comparison to produce the needed boolean.
if (char c = GetChar() < ' ')
TranslateWhiteSpace(c);
Sean
"Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message
news:3CA335AA.E367FCB4 deming-os.org...

BOGGLE...here's a weird idea. What if you could declare a named switch,
kind of like declaring a variable?
int myVar switch(foo.bar().baz().fred().wilma().barney())
{
case 0..12:
DoStuff(myVar); break;
default:
DoOtherStuff(myVar);
}
The scope of the variable would be just the switch block. Or what about
this syntax:
switch(foo.bar().baz().fred().wilma().barney()) as in myVar {...}
Thoughts?

I just can't see why you can't merely do this:
int myVar = foo.bar().baz().fred().wilma().barney();
switch (myVar)

Because myVar will now be clattering the namespace, while it's
only needed _inside_ the switch (like in most cases the
loop counter is only needed inside the loop).
Of course, an additional pair of braces could be added...
but it is a hack.

How about this code:
switch(foo.bar().baz().fred().wilma().barney())
{
case 0..12:
blah
break;
default:
blah2
break;
}
It would be cool to have a keyword/automatic variable that contains the
value that was put into th switch() clause so that I don't have to call
the long string of functions again (or to have a temporary variable).

I hate to be a nay-sayer for interesting ideas... but some things are too
easily done to be worth simplifying further.
I can't think of any problem with saying:
int c = foo.bar().baz().fred().wilma().barney();
switch(c) {
But one other suggestion, that of putting the declaration in the switch, as
in "switch(int c = foo.bar().baz().fred().wilma().barney())", suggests the
notion that a declaration with an initializer is an expression with a value.
That might be worth thinking about.
--
Richard Krehbiel, Arlington, VA, USA
rich kastle.com (work) or krehbiel3 comcast.net (personal)