D - Python inspirations
- Matthew Wilson (13/13) Apr 10 2003 Being doing Python of late, and am impressed with some of the nice featu...
 - J C Calvarese (6/26) Apr 10 2003 You've got my interest. That sounds useful. Should we consider
 - Matthew Wilson (17/43) Apr 10 2003 For me I don't see the need for a new keyword, partly because I'm aware ...
 - Dan Liebgold (32/38) Apr 10 2003 No! This type of syntax is misleading, especially in the case of the wh...
 - Luna Kid (6/19) Apr 10 2003 I've seen this mentioned somewhere in this NG.
 - DDevil (20/35) Apr 10 2003 Why not use the exception mechanism?
 - Matthew Wilson (3/38) Apr 10 2003 Notwithstanding other objections, there's the issue of performance.
 - DDevil (19/20) Apr 10 2003 Well then there's always goto (braces added for clarity).
 - Patrick Down (3/5) Apr 10 2003 I'm all for it. I've made the same sugestion here before.
 - Stephen Waits (4/7) Apr 12 2003 Matt,
 - Walter (14/27) May 23 2003 features.
 - Matthew Wilson (5/36) May 27 2003 What if there are multiple breaks?
 - Walter (5/46) Jun 06 2003 You can use:
 
Being doing Python of late, and am impressed with some of the nice features.
One in particular I've always thought would be nice to have in C or C++ is
for-else, as in
for(int i = 0; i < 10; ++i)
{
    // do some stuff
}
else
{
    /// This only called if the for loop is terminated with a break
statement.
}
Any takers for D?
 Apr 10 2003
You've got my interest.  That sounds useful.  Should we consider
calling it something new like "forelse" for example?  How costly is 
having a new keyword when it's much easiler for the uninitiated to guess 
what's going on?
Justin
Matthew Wilson wrote:
 Being doing Python of late, and am impressed with some of the nice features.
 
 One in particular I've always thought would be nice to have in C or C++ is
 for-else, as in
 
 for(int i = 0; i < 10; ++i)
 {
     // do some stuff
 
 }
 else
 {
     /// This only called if the for loop is terminated with a break
 statement.
 }
 
 Any takers for D?
 
 
 
 Apr 10 2003
For me I don't see the need for a new keyword, partly because I'm aware how
phobic language designers hate adding reserved words. But also, it seems
that else-ing constructs is something that we may want to extend, so else
becomes something of a general concept (which it is anyway, I guess).
For example, there's no reason why we wouldn't also use it for `while` as
well as `for` as in
while(!b)
{
}
else
{
  // This is called if the while was broken
}
"J C Calvarese" <jcc-47 excite.com> wrote in message
news:b74qdr$3rd$1 digitaldaemon.com...
 You've got my interest.  That sounds useful.  Should we consider
 calling it something new like "forelse" for example?  How costly is
 having a new keyword when it's much easiler for the uninitiated to guess
 what's going on?
 Justin
 Matthew Wilson wrote:
 Being doing Python of late, and am impressed with some of the nice
features.
 One in particular I've always thought would be nice to have in C or C++
is
 for-else, as in
 for(int i = 0; i < 10; ++i)
 {
     // do some stuff
 }
 else
 {
     /// This only called if the for loop is terminated with a break
 statement.
 }
 Any takers for D?
 Apr 10 2003
No!  This type of syntax is misleading, especially in the case of the while
loop.  It seems like the else would be executed when the condition were *never*
true.  For example:
if (test) {
}
else {
// executed when test false
}
versus...
while (test) {
}
else {
// not necessarily executed when test false, instead connected with a break
statement (!!?)
}
The for loop version isn't much better...   I think this can already be done if
function literal expressions were extended slightly to allow an immediate call,
for example:
thing find_thing (char[] thing_name) {
if (delegate thing(name) { for (int i =0; i < COUNT; ++i) { /* look for name */
return found_thing; }(thing_name)) {
// executed if found
}
else {
// executed if not found  
}
}
It looks odd, but it really isn't! ;)     The scoping doesn't change, and you
can pass back any type you like (so you could embed such an immediate literal
call in a switch for example). The trick is to format the code better....
Dan
In article <b74red$4c8$1 digitaldaemon.com>, Matthew Wilson says...
For me I don't see the need for a new keyword, partly because I'm aware how
phobic language designers hate adding reserved words. But also, it seems
that else-ing constructs is something that we may want to extend, so else
becomes something of a general concept (which it is anyway, I guess).
For example, there's no reason why we wouldn't also use it for `while` as
well as `for` as in
 Apr 10 2003
I've seen this mentioned somewhere in this NG. And I sort of like it, too. Luna Kid "Matthew Wilson" <dmd synesis.com.au> wrote in message news:b74p8g$35v$2 digitaldaemon.com...Being doing Python of late, and am impressed with some of the nicefeatures.One in particular I've always thought would be nice to have in C or C++ is for-else, as in for(int i = 0; i < 10; ++i) { // do some stuff } else { /// This only called if the for loop is terminated with a break statement. } Any takers for D?
 Apr 10 2003
Why not use the exception mechanism?
try
{
   for (int i = 0; i < 10; i++)
   {
      // Do stuff
      ...
      if (something)
         throw(Error); // Instead of break
   }
}
catch (Error)
{
   // Do stuff here if exception (break)
}
Of course that doesn't look quite as minimalistic, but the behavior is
possibly more explicit and clear.
--
// DDevil
On Fri, 11 Apr 2003 07:56:02 +1000, Matthew Wilson wrote:
 Being doing Python of late, and am impressed with some of the nice
 features.
 
 One in particular I've always thought would be nice to have in C or C++
 is for-else, as in
 
 for(int i = 0; i < 10; ++i)
 {
     // do some stuff
 }
 else
 {
     /// This only called if the for loop is terminated with a break
 statement.
 }
 Apr 10 2003
Notwithstanding other objections, there's the issue of performance.
"DDevil" <ddevil functionalfuture.com> wrote in message
news:pan.2003.04.11.00.35.05.574731 functionalfuture.com...
 Why not use the exception mechanism?
 try
 {
    for (int i = 0; i < 10; i++)
    {
       // Do stuff
       ...
       if (something)
          throw(Error); // Instead of break
    }
 }
 catch (Error)
 {
    // Do stuff here if exception (break)
 }
 Of course that doesn't look quite as minimalistic, but the behavior is
 possibly more explicit and clear.
 --
 // DDevil
 On Fri, 11 Apr 2003 07:56:02 +1000, Matthew Wilson wrote:
 Being doing Python of late, and am impressed with some of the nice
 features.
 One in particular I've always thought would be nice to have in C or C++
 is for-else, as in
 for(int i = 0; i < 10; ++i)
 {
     // do some stuff
 }
 else
 {
     /// This only called if the for loop is terminated with a break
 statement.
 }
 Apr 10 2003
Well then there's always goto (braces added for clarity).
for (int i = 0; i < 10; i++)
{
   // Do stuff
   ...
   if (something)
      goto Error; // Instead of break
}
goto Done;
{
   Error:
   // Do stuff here for the break condition
}
Done:
// Code continues
It's fast anyway.  ;-)
--
// DDevil
On Fri, 11 Apr 2003 11:28:55 +1000, Matthew Wilson wrote:
 Notwithstanding other objections, there's the issue of performance.
 Apr 10 2003
"Matthew Wilson" <dmd synesis.com.au> wrote in news:b74p8g$35v$2 digitaldaemon.com:One in particular I've always thought would be nice to have in C or C++ is for-else, as inI'm all for it. I've made the same sugestion here before.
 Apr 10 2003
Matthew Wilson wrote:One in particular I've always thought would be nice to have in C or C++ is for-else, as inMatt, Sadly I have to say this is insanely ugly. --Steve
 Apr 12 2003
"Matthew Wilson" <dmd synesis.com.au> wrote in message news:b74p8g$35v$2 digitaldaemon.com...Being doing Python of late, and am impressed with some of the nicefeatures.One in particular I've always thought would be nice to have in C or C++ is for-else, as in for(int i = 0; i < 10; ++i) { // do some stuff } else { /// This only called if the for loop is terminated with a break statement. } Any takers for D?How about: for (int i = 0; i < 10; ++i) { // do some stuff if (condition) { // This only executed if the for loop is terminated with a break statement break; } }
 May 23 2003
What if there are multiple breaks? (I know, I know: local functions) "Walter" <walter digitalmars.com> wrote in message news:bampoi$10mn$2 digitaldaemon.com..."Matthew Wilson" <dmd synesis.com.au> wrote in message news:b74p8g$35v$2 digitaldaemon.com...isBeing doing Python of late, and am impressed with some of the nicefeatures.One in particular I've always thought would be nice to have in C or C++for-else, as in for(int i = 0; i < 10; ++i) { // do some stuff } else { /// This only called if the for loop is terminated with a break statement. } Any takers for D?How about: for (int i = 0; i < 10; ++i) { // do some stuff if (condition) { // This only executed if the for loop is terminated with a break statement break; } }
 May 27 2003
You can use:
    break label;
"Matthew Wilson" <matthew stlsoft.org> wrote in message
news:bb1gip$2j6s$1 digitaldaemon.com...
 What if there are multiple breaks?
 (I know, I know: local functions)
 "Walter" <walter digitalmars.com> wrote in message
 news:bampoi$10mn$2 digitaldaemon.com...
 "Matthew Wilson" <dmd synesis.com.au> wrote in message
 news:b74p8g$35v$2 digitaldaemon.com...
 Being doing Python of late, and am impressed with some of the nice
 features.
 One in particular I've always thought would be nice to have in C or
C++
 is
 for-else, as in
 for(int i = 0; i < 10; ++i)
 {
     // do some stuff
 }
 else
 {
     /// This only called if the for loop is terminated with a break
 statement.
 }
 Any takers for D?
 How about:
 for (int i = 0; i < 10; ++i)
 {
     // do some stuff
     if (condition)
     {
         // This only executed if the for loop is terminated with a break
 statement
         break;
     }
 }
 Jun 06 2003








 
 
 
 Dan Liebgold <Dan_member pathlink.com> 