www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Another syntactic under-performer

reply "Bill Baxter" <wbaxter gmail.com> writes:
The colon.  I think this may be another piece of syntax that could be
better used.

In particular its use in goto and switch labels.  I've seen a few
interesting proposals that wanted to use colons but which ran into
troubles with ambiguity vs goto and switch labels.   But switch case
labels are already inside a syntactically distinct structure, so it
should be easy to change them to just about any syntax.   And the more
generic labeled statements used for goto targets appear relatively
infrequently (*), so hogging the colon just for those is wasteful.   A
more verbose syntax would work fine for these.  Like maybe a context
keyword on goto:   "goto(label) FINISHED"

With the colon freed up to use in another statement or expression it
could be made part of a lambda syntax or something.

Just a thought.

--bb
(* except in Walter's code  :-P  )
Oct 13 2008
next sibling parent "Chris R. Miller" <lordsauronthegreat gmail.com> writes:
Bill Baxter wrote:
 The colon.  I think this may be another piece of syntax that could be
 better used.
 
 In particular its use in goto and switch labels.  I've seen a few
 interesting proposals that wanted to use colons but which ran into
 troubles with ambiguity vs goto and switch labels.   But switch case
 labels are already inside a syntactically distinct structure, so it
 should be easy to change them to just about any syntax.   And the more
 generic labeled statements used for goto targets appear relatively
 infrequently (*), so hogging the colon just for those is wasteful.   A
 more verbose syntax would work fine for these.  Like maybe a context
 keyword on goto:   "goto(label) FINISHED"
 
 With the colon freed up to use in another statement or expression it
 could be made part of a lambda syntax or something.
 
 Just a thought.
 
 --bb
 (* except in Walter's code  :-P  )
What about modifying foreach? I may be unpopular for saying this, but use use of the semicolon in foreach is misleading. The reason for using the semicolon in the for loop is to signify distinct statements. It is for this reason that in Java 1.5 they used the colon in their foreach (aka the "new" for loop, they didn't bother adding the "each"), sorta like this: ArrayList<int> IntList=new ArrayList<int>(); IntList.add(1); IntList.add(2); IntList.add(3); for(int i:IntList) // System.out.println(i); IMHO this is not misleading (but not ideal). By contrast D's current foreach: foreach(int i;IntList) printf("%d\n",i); IMHO ideal would be more like this, using the "in" operator: foreach(int i in IntList) I'm unsure of possible precedence collisions inherent in that syntax, but on the bright side you could implement it alongside the existing syntax without problems. I just wanted to float these ideas past, since it was somewhat on-topic.
Oct 13 2008
prev sibling parent reply ore-sama <spam here.lot> writes:
Bill Baxter Wrote:

 I've seen a few
 interesting proposals that wanted to use colons but which ran into
 troubles with ambiguity vs goto and switch labels.   But switch case
 labels are already inside a syntactically distinct structure, so it
 should be easy to change them to just about any syntax.
there was interesting proposal for if-style case statement, which gives real structure to switch statement! http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=77141
Oct 14 2008
parent reply "Bill Baxter" <wbaxter gmail.com> writes:
On Tue, Oct 14, 2008 at 4:59 PM, ore-sama <spam here.lot> wrote:
 Bill Baxter Wrote:

 I've seen a few
 interesting proposals that wanted to use colons but which ran into
 troubles with ambiguity vs goto and switch labels.   But switch case
 labels are already inside a syntactically distinct structure, so it
 should be easy to change them to just about any syntax.
there was interesting proposal for if-style case statement, which gives real structure to switch statement! http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=77141
I saw the thread. Like some others, I didn't really get the need for that particular change. I'd give it another look right now, but unfortunately links to that web-news interface don't work right. :-( That link goes to an unrelated discussion. --bb
Oct 14 2008
parent reply ore-sama <spam here.lot> writes:
Bill Baxter Wrote:

 http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=77141
I saw the thread. Like some others, I didn't really get the need for that particular change. I'd give it another look right now, but unfortunately links to that web-news interface don't work right. :-( That link goes to an unrelated discussion. --bb
script has problem with art_group parameter, edit it manually to hold real group name: art_group=digitalmars.D art_group=digitalmars.D.announce art_group=digitalmars.D.learn
Oct 14 2008
next sibling parent "Bill Baxter" <wbaxter gmail.com> writes:
On Tue, Oct 14, 2008 at 5:19 PM, ore-sama <spam here.lot> wrote:
 Bill Baxter Wrote:

 http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=77141
I saw the thread. Like some others, I didn't really get the need for that particular change. I'd give it another look right now, but unfortunately links to that web-news interface don't work right. :-( That link goes to an unrelated discussion. --bb
script has problem with art_group parameter, edit it manually to hold real group name: art_group=digitalmars.D art_group=digitalmars.D.announce art_group=digitalmars.D.learn
Sorry I just missed it. --bb
Oct 14 2008
prev sibling parent reply "Bill Baxter" <wbaxter gmail.com> writes:
On Tue, Oct 14, 2008 at 5:25 PM, Bill Baxter <wbaxter gmail.com> wrote:
 On Tue, Oct 14, 2008 at 5:19 PM, ore-sama <spam here.lot> wrote:
 Bill Baxter Wrote:

 http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=77141
I saw the thread. Like some others, I didn't really get the need for that particular change. I'd give it another look right now, but unfortunately links to that web-news interface don't work right. :-( That link goes to an unrelated discussion. --bb
script has problem with art_group parameter, edit it manually to hold real group name: art_group=digitalmars.D art_group=digitalmars.D.announce art_group=digitalmars.D.learn
Sorry I just missed it.
The proposal was this: """ 4. Replace C-style switch with something modern and more D-like: switch (x) { case (0) foo(); case (1) { bar(); baz(); } else throw new Exception("nope"); } """ The question is why? Replacing syntax just to look "more modern" is not a good justification for breaking everyone's code. But if you have the goal of freeing up the colon for bigger and better things, I suppose that doesn't seem like a bad syntax. I don't think it would kill the Duff's device, either. It's just a different syntax for the current switch. Excuse me now.. while I "free up my colon for bigger and better things". --bb
Oct 14 2008
parent reply ore-sama <spam here.lot> writes:
Bill Baxter Wrote:

 It's just a different syntax for the current switch.
as it was noted, current case is just a type of label. In this proposal case is a scope statement like if.
Oct 14 2008
parent "Bill Baxter" <wbaxter gmail.com> writes:
On Tue, Oct 14, 2008 at 6:05 PM, ore-sama <spam here.lot> wrote:
 Bill Baxter Wrote:

 It's just a different syntax for the current switch.
as it was noted, current case is just a type of label. In this proposal case is a scope statement like if.
Ah, I see. Well, it's really a different goal than this thread in that case. But very similar syntax could be used with current switch semantics to help free up the colon. --bb
Oct 14 2008