Jump to page: 1 2 3
Thread overview
Suggestion: way to get switch() value
Mar 27, 2002
Russ Lewis
Mar 27, 2002
Pavel Minayev
Mar 27, 2002
OddesE
Mar 27, 2002
Christophe Bouchon
Mar 28, 2002
Pavel Minayev
Mar 27, 2002
Stephen Fuld
Mar 27, 2002
OddesE
Mar 28, 2002
DrWhat?
Mar 28, 2002
Pavel Minayev
Mar 28, 2002
DrWhat?
Mar 28, 2002
Pavel Minayev
Mar 28, 2002
DrWhat?
Mar 28, 2002
Pavel Minayev
Mar 28, 2002
Russ Lewis
TYPO AGAIN
Mar 28, 2002
Russ Lewis
Mar 28, 2002
Pavel Minayev
Mar 28, 2002
Ben Cohen
Mar 28, 2002
Russ Lewis
Mar 28, 2002
Sean L. Palmer
Mar 28, 2002
Pavel Minayev
Apr 23, 2002
Walter
Apr 23, 2002
Pavel Minayev
Apr 24, 2002
Walter
Mar 28, 2002
Richard Krehbiel
Mar 28, 2002
Sean L. Palmer
Mar 28, 2002
Richard Krehbiel
March 27, 2002
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))) ]


March 27, 2002
"Russ Lewis" <spamhole-2001-07-16@deming-os.org> wrote in message news:3CA22EAD.6CFF0221@deming-os.org...

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


March 27, 2002
"Russ Lewis" <spamhole-2001-07-16@deming-os.org> wrote in message news:3CA22EAD.6CFF0221@deming-os.org...
> 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))) ]
>

Do you mean something like this?

switch(foo.bar().baz().fred().wilma().barney())
{
    case 0..12:
        Func (caseval);
        break;
    default:
        Func (caseval +2);
        break;
}

I like it, kinda like 'this' for objects.


--
Stijn
OddesE_XYZ@hotmail.com
http://OddesE.cjb.net
_________________________________________________
Remove _XYZ from my address when replying by mail



March 27, 2002
"Pavel Minayev" <evilone@omen.ru> wrote in message news:a7te3p$2og9$1@digitaldaemon.com...
> "Russ Lewis" <spamhole-2001-07-16@deming-os.org> wrote in message news:3CA22EAD.6CFF0221@deming-os.org...
>
> > 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...
>
>

Cool yes.
Better than 'caseval' anyway (see my other reply)... :)


--
Stijn
OddesE_XYZ@hotmail.com
http://OddesE.cjb.net
_________________________________________________
Remove _XYZ from my address when replying by mail



March 27, 2002
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:
> "Russ Lewis" <spamhole-2001-07-16@deming-os.org> wrote in message news:3CA22EAD.6CFF0221@deming-os.org...
>
> > 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...



March 27, 2002
"Pavel Minayev" <evilone@omen.ru> wrote in message news:a7te3p$2og9$1@digitaldaemon.com...
> "Russ Lewis" <spamhole-2001-07-16@deming-os.org> wrote in message news:3CA22EAD.6CFF0221@deming-os.org...
>
> > 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


March 28, 2002
"Christophe Bouchon" <cbouchon@hotmail.com> wrote in message news:a7tlvg$2si8$1@digitaldaemon.com...

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

Yes. If one really need "it" from upper level, he can always catch it:

    switch (foo)
    {
    case 1:
        that = it;
        switch (bar)
        {
        case 2:
            that.does(it);
        }
    }

> 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

It would be great; unfortunately, D doesn't support variable declaration
in switch() and with() blocks...

> 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:
> > "Russ Lewis" <spamhole-2001-07-16@deming-os.org> wrote in message news:3CA22EAD.6CFF0221@deming-os.org...
> >
> > > 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...
>
>
>


March 28, 2002
Russ Lewis 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).
> 
        switch( temp = foo.bar().baz().fred().wilma().barney() )
        { ... }

        Why not?

C       2002/3/28


March 28, 2002
"DrWhat?" <blackmarlin@nospam.asean-mail.com> wrote in message news:a7v17r$ger$3@digitaldaemon.com...

>         switch( temp = foo.bar().baz().fred().wilma().barney() )
>         { ... }
>
>         Why not?

'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?


March 28, 2002
Pavel Minayev wrote:

> "DrWhat?" <blackmarlin@nospam.asean-mail.com> wrote in message news:a7v17r$ger$3@digitaldaemon.com...
> 
>>         switch( temp = foo.bar().baz().fred().wilma().barney() )
>>         { ... }
>>
>>         Why not?
> 
> '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.
« First   ‹ Prev
1 2 3