www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1053] New: Make 'static else if' or 'static if (...) {...} else if' work

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1053

           Summary: Make 'static else if' or 'static if (...) {...} else if'
                    work
           Product: D
           Version: 1.008
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: wbaxter gmail.com


It would be nice if "else static if" could be written "static else if".  Or
even better just "else if".

"else static if" struck me as odd the first time I saw it, and since then I
continue to mistype it as "static else if" pretty much every time I use it.  


So it would be great if "static else if" just worked.  

On the other hand, I'm pretty sure 
  static if (foo) { }
  else if (bar) { } 
is an error currently, so it would be nice if that were just taken to be a
"static else if".  There isn't a "static else {}" so why should we have to
repeat the "static" on an "else if"?  One "static" should be enough.

I guess this could be an issue?:
  static if (foo) 
     if (biff)
         single_statement();
  else if (bar) { } 

But I could live without being able to do that.  Oh, and besides that it's
already ambiguous with plain ifs...
  if (foo) 
     if (biff)
         single_statement();
  else if (bar) { } 

Exactly the same deal -- who does the else belong to?

--
As an added bonus either of these changes would make the Emacs D-mode capable
of indenting static ifs with else ifs properly.  That's not a sufficient reason
to make the change (emacs D-mode could be made to work somehow) But the fact
that cc-mode basically sees "else static if" as an aberration was the thing
that finally drove me to file an enhancement request on this.


-- 
Mar 11 2007
next sibling parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
<d-bugmail puremagic.com> wrote in message 
news:bug-1053-3 http.d.puremagic.com/issues/...
 http://d.puremagic.com/issues/show_bug.cgi?id=1053

           Summary: Make 'static else if' or 'static if (...) {...} else 
 if'
                    work
           Product: D
           Version: 1.008
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: wbaxter gmail.com


 It would be nice if "else static if" could be written "static else if". 
 Or
 even better just "else if".

 "else static if" struck me as odd the first time I saw it, and since then 
 I
 continue to mistype it as "static else if" pretty much every time I use 
 it.

Then stop typing it that way ;)
 So it would be great if "static else if" just worked.

 On the other hand, I'm pretty sure
  static if (foo) { }
  else if (bar) { }
 is an error currently, so it would be nice if that were just taken to be a
 "static else if".  There isn't a "static else {}" so why should we have to
 repeat the "static" on an "else if"?  One "static" should be enough.

It's not. "static if" is a statement of its own, and "if" is a statement of its own. This: static if(foo) {} else if(bar) {} is legal. It means if foo evaluates to true, compile in the static if's body. Otherwise, compile in the "if(bar) {}" statement. There's no "static else" because the grammar for static if is "static if(cond) statment 'else' statement'. So you chain static ifs with "static if(){} else static if(){}" because "static if" is a statement, and it comes after that "else".
 Oh, and besides that it's
 already ambiguous with plain ifs...
  if (foo)
     if (biff)
         single_statement();
  else if (bar) { }

 Exactly the same deal -- who does the else belong to?

It belongs to the if(biff) statement.
 As an added bonus either of these changes would make the Emacs D-mode 
 capable
 of indenting static ifs with else ifs properly.  That's not a sufficient 
 reason
 to make the change (emacs D-mode could be made to work somehow) But the 
 fact
 that cc-mode basically sees "else static if" as an aberration was the 
 thing
 that finally drove me to file an enhancement request on this.

Unfortunately I think this would make the grammar needlessly complicated. And don't use emacs; use vim ;)
Mar 11 2007
parent reply Bill Baxter <dnewsgroup billbaxter.com> writes:
Jarrett Billingsley wrote:
 <d-bugmail puremagic.com> wrote in message 
 news:bug-1053-3 http.d.puremagic.com/issues/...

 Unfortunately I think this would make the grammar needlessly complicated.

 

Maybe perl/python/ruby/cpp/tcl were right. Else if should be a single keyword. Then it wouldn't be an issue.
 And don't use emacs; use vim ;)

I can't live without my M-x hanoi. --bb
Mar 11 2007
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Bill Baxter" <dnewsgroup billbaxter.com> wrote in message 
news:et2qs5$2okg$1 digitalmars.com...
 Maybe perl/python/ruby/cpp/tcl were right.  Else if should be a single 
 keyword.  Then it wouldn't be an issue.

Phh.. that's because their grammars aren't as flexible ;) But C++ doesn't have "elseif" as a single word. Maybe you're thinking of the "#elif" preprocessor command?
 I can't live without my M-x hanoi.

lol.
Mar 12 2007
parent reply Frits van Bommel <fvbommel REMwOVExCAPSs.nl> writes:
Jarrett Billingsley wrote:
 "Bill Baxter" <dnewsgroup billbaxter.com> wrote in message 
 news:et2qs5$2okg$1 digitalmars.com...
 Maybe perl/python/ruby/cpp/tcl were right.  Else if should be a single 
 keyword.  Then it wouldn't be an issue.

Phh.. that's because their grammars aren't as flexible ;) But C++ doesn't have "elseif" as a single word. Maybe you're thinking of the "#elif" preprocessor command?

I didn't see 'c++' mentioned, only 'cpp', which is (confusingly) also a common acronym for the C (or C++) pre-processor. So I'd guess he was indeed thinking of #elif :).
Mar 12 2007
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Frits van Bommel" <fvbommel REMwOVExCAPSs.nl> wrote in message 
news:et3mrr$14cu$2 digitalmars.com...

 I didn't see 'c++' mentioned, only 'cpp', which is (confusingly) also a 
 common acronym for the C (or C++) pre-processor. So I'd guess he was 
 indeed thinking of #elif :).

Ohh! That's right. You're probably right.
Mar 12 2007
parent Bill Baxter <dnewsgroup billbaxter.com> writes:
Jarrett Billingsley wrote:
 "Frits van Bommel" <fvbommel REMwOVExCAPSs.nl> wrote in message 
 news:et3mrr$14cu$2 digitalmars.com...
 
 I didn't see 'c++' mentioned, only 'cpp', which is (confusingly) also a 
 common acronym for the C (or C++) pre-processor. So I'd guess he was 
 indeed thinking of #elif :).

Ohh! That's right. You're probably right.

Yep. That's what I meant. --bb
Mar 12 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1053





------- Comment #2 from wbaxter gmail.com  2007-03-12 18:35 -------
(For the record, there was some discussion on this on the newsgroup Frits'
message above was in reply to something there about which languages use an
'elseif' keyword).

Anyway, I can see the difficulties involved in the implementation of this, but
I still think it would make D better for users.  In the end, it's just an
enhancement request.  If Walter agrees then maybe something will be done about
it, if not then he'll close it.

But here's another attempt to sell the idea: I'm pretty sure there are very few
C/C++/D/Java users who really think of 

if () {
}
else if () {
}
else if () {
}
else () {
}

as this:

if () {
}
else {
   if () {
   }
   else {
       if () {
       }
       else () {
       }
   }
}

which is pretty much the way you have to be thinking for 'else static if' to
make sense.


-- 
Mar 12 2007
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1053


deewiant gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|1.008                       |1.009




------- Comment #3 from deewiant gmail.com  2007-03-17 12:03 -------
That _is_ the way I often think of if-else. :-P I prefer the way it currently
works, as I do sometimes write:

static if
else if

And it means what I want it to mean.

Sometimes, though, I find that it's clearer to write something as:

if
else {
  if
  else
}

Instead of:

if
else if
else

Depending on what exactly is in the first else.

"static else if" would complicate the grammar a bit (written in about a minute,
not sure if the following would be correct):
  if: "if [expression] [statement] (else [statement])"
  static if: "[static if [expression] [statement] (else [statement])] | [static
if [expression] [statement] (static else [if-statement])]"

As opposed to the current:
  if or static if: "(static) if [expression] [statement] (else [statement])"


-- 
Mar 17 2007