digitalmars.D - Another syntactic under-performer
- Bill Baxter (16/16) Oct 13 2008 The colon. I think this may be another piece of syntax that could be
- Chris R. Miller (23/43) Oct 13 2008 What about modifying foreach? I may be unpopular for saying this, but
- ore-sama (3/8) Oct 14 2008 there was interesting proposal for if-style case statement, which gives ...
- Bill Baxter (7/15) Oct 14 2008 I saw the thread. Like some others, I didn't really get the need for
- ore-sama (5/15) Oct 14 2008 script has problem with art_group parameter, edit it manually to hold re...
- Bill Baxter (4/19) Oct 14 2008 Oh wait.. that was the right post. It was just #4 out of 4 points.
- Bill Baxter (23/43) Oct 14 2008 The proposal was this:
- ore-sama (2/3) Oct 14 2008 as it was noted, current case is just a type of label. In this proposal ...
- Bill Baxter (5/8) Oct 14 2008 Ah, I see. Well, it's really a different goal than this thread in
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
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
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
On Tue, Oct 14, 2008 at 4:59 PM, ore-sama <spam here.lot> wrote:Bill Baxter Wrote: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. --bbI'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
Bill Baxter Wrote: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.learnhttp://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=77141I 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
On Tue, Oct 14, 2008 at 5:19 PM, ore-sama <spam here.lot> wrote:Bill Baxter Wrote:Sorry I just missed it. --bbscript 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.learnhttp://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=77141I 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
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: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". --bbBill Baxter Wrote:Sorry I just missed it.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.learnhttp://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=77141I 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
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
On Tue, Oct 14, 2008 at 6:05 PM, ore-sama <spam here.lot> wrote:Bill Baxter Wrote: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. --bbIt'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