Re: How to complex switch?

2011-05-26 Thread Stewart Gordon
On 17/05/2011 21:44, Stewart Gordon wrote: Features to improve the readability of code are the very definition of syntactic sugar. Indeed, Prolog programmers rely on syntactic sugar a lot. Come to think of it, some of the everyday features of programming languages generally are syntactic su

Re: How to complex switch?

2011-05-26 Thread Stewart Gordon
On 17/05/2011 21:50, Daniel Gibson wrote: Am 17.05.2011 22:44, schrieb Stewart Gordon: Could you be thinking of syntactic saccharin? Sweet syntax with a disgusting bitter aftertaste? ;) I guess that would make sense. But actually, syntactic saccharin is something that may look at first l

Re: Builtin regex (Was: How to complex switch?)

2011-05-19 Thread Timon Gehr
Andrei Alexandrescu wrote: > Timon Gehr wrote: > > > > 1. Deprecate using CommaExpression inside ParanthesizedExpression. (This > > does not > > affect most code that uses the comma operator!) > > 2. Wait a few releases. > > 3. Introduce straightforward, built-in tuples: > [snip] > > We've been th

Re: Builtin regex (Was: How to complex switch?)

2011-05-18 Thread bearophile
Andrei: > One possibility that I hadn't thought before is to use ";" for > separating tuple elements. Upon a casual inspection, it turns out no > statement can be enclosed directly in "(" and ")" so there's no > ambiguity. It would also take care of the issue "did you mean to pass > them as fu

Re: Builtin regex (Was: How to complex switch?)

2011-05-18 Thread Andrei Alexandrescu
On 5/18/11 5:12 PM, Timon Gehr wrote: Timon Gehr: Library code should make use of the language to implement its semantics. Not the other way round. Why? Short story: Obvious? Do you really want to make some non-built-in types more equal than others? Why would you want to have a dependency

Re: Builtin regex (Was: How to complex switch?)

2011-05-18 Thread Timon Gehr
> Timon Gehr: > > > Library code should make use of the language to implement its semantics. > > Not the other way round. > > Why? Short story: Obvious? Do you really want to make some non-built-in types more equal than others? Why would you want to have a dependency cycle between std and the com

Re: Builtin regex (Was: How to complex switch?)

2011-05-18 Thread bearophile
Timon Gehr: > Library code should make use of the language to implement its semantics. > Not the other way round. Why? > Another reason I dislike it: it looks different to other "tuple literals" > that are already built-in: > > foo (note, how, this, is, a, tuple, "!"); Looking different from

Re: Builtin regex (Was: How to complex switch?)

2011-05-18 Thread Timon Gehr
> Timon Gehr: > >> Tuple literals would indeed be very nice. > > I have asked for tuple unpacking syntax (and other things like some support > from the type system). Tuple literals are less needed. > >> (having syntactic sugar for phobos functionality in the language >> seems like a very bad desig

Re: Builtin regex (Was: How to complex switch?)

2011-05-17 Thread bearophile
Timon Gehr: > Tuple literals would indeed be very nice. I have asked for tuple unpacking syntax (and other things like some support from the type system). Tuple literals are less needed. > (having syntactic sugar for phobos functionality in the language > seems like a very bad design to me, I

Re: Builtin regex (Was: How to complex switch?)

2011-05-17 Thread Timon Gehr
> Stewart Gordon: > > > I think D is going the right way on the whole by leaving regexps to a > > library. Though > > this does limit such possibilities as optimised regexp switches. > > Leaving regexps to a library is an acceptable choice for D, or maybe even the best choice. In D even associati

Re: How to complex switch?

2011-05-17 Thread Daniel Gibson
Am 17.05.2011 22:44, schrieb Stewart Gordon: > On 12/05/2011 13:21, Matthew Ong wrote: >> @dennis luehring > >> I do not think that this is syntactic sugar. Compare this 2 block of >> code. Which >> is easier to read? > > > Features to improve the readability of code are the very definition of >

Re: How to complex switch?

2011-05-17 Thread Stewart Gordon
On 12/05/2011 13:21, Matthew Ong wrote: @dennis luehring I do not think that this is syntactic sugar. Compare this 2 block of code. Which is easier to read? Features to improve the readability of code are the very definition of syntactic sugar. Indeed, Prolog programmers rely on syntactic

Re: Builtin regex (Was: How to complex switch?)

2011-05-17 Thread bearophile
Stewart Gordon: > I think D is going the right way on the whole by leaving regexps to a > library. Though > this does limit such possibilities as optimised regexp switches. Leaving regexps to a library is an acceptable choice for D, or maybe even the best choice. In D even associative arrays

Re: Builtin regex (Was: How to complex switch?)

2011-05-17 Thread Stewart Gordon
On 13/05/2011 06:10, KennyTM~ wrote: On May 13, 11 12:14, Ary Manzana wrote: I didn't use regex a lot before I started using Ruby. The thing is, in Ruby it's so easy to use regex that I just started using them a lot more than before. Of course, ruby has built-in operators for matching regexs,

Re: Builtin regex (Was: How to complex switch?)

2011-05-16 Thread Matthew Ong
Hi, Seems like some people also had the same idea about D supporting more complex switch syntax and given more interesting reasons. Perhaps can be consider for D 3.0 or ... I am new here, please understand, but wish to see D take off because I do see some nice syntax in D.

Re: Builtin regex (Was: How to complex switch?)

2011-05-15 Thread Jacob Carlborg
On 2011-05-13 14:59, Ary Manzana wrote: On 5/13/11 12:10 PM, KennyTM~ wrote: On May 13, 11 12:14, Ary Manzana wrote: On 5/12/11 6:42 PM, KennyTM~ wrote: On May 12, 11 19:13, Matthew Ong wrote: Hi All, Anyway to include this cool feature of switch with D in the near future? Why the obsessio

Re: Builtin regex (Was: How to complex switch?)

2011-05-14 Thread Robert Clipsham
On 13/05/2011 17:52, Dmitry Olshansky wrote: When you've written a couple it doesn't take much to get it right in my experience. I don't find them hard to maintain personally, I guess that comes from experience though. What do you mean port? Literally code the same in another programming langua

Re: Builtin regex (Was: How to complex switch?)

2011-05-13 Thread Dmitry Olshansky
On 13.05.2011 20:00, Robert Clipsham wrote: On 13/05/2011 16:12, Dmitry Olshansky wrote: Regex is ugly, impossible to maintain/debug and slow for anything mildly complicated - a handwritten parser is magnitudes faster, and easy to understand, maintain and debug. If it's simple, you may as well w

Re: Builtin regex (Was: How to complex switch?)

2011-05-13 Thread Robert Clipsham
On 13/05/2011 16:12, Dmitry Olshansky wrote: Regex is ugly, impossible to maintain/debug and slow for anything mildly complicated - a handwritten parser is magnitudes faster, and easy to understand, maintain and debug. If it's simple, you may as well write a couple of extra lines and have it be a

Re: Builtin regex (Was: How to complex switch?)

2011-05-13 Thread Dmitry Olshansky
On 13.05.2011 19:35, Dmitry Olshansky wrote: On 13.05.2011 19:26, KennyTM~ wrote: On May 13, 11 23:12, Dmitry Olshansky wrote: On 13.05.2011 18:25, Robert Clipsham wrote: On 13/05/2011 05:14, Ary Manzana wrote: How about making regex a built-in feature with this syntax: /regex/ ? I didn't us

Re: Builtin regex (Was: How to complex switch?)

2011-05-13 Thread Dmitry Olshansky
On 13.05.2011 19:26, KennyTM~ wrote: On May 13, 11 23:12, Dmitry Olshansky wrote: On 13.05.2011 18:25, Robert Clipsham wrote: On 13/05/2011 05:14, Ary Manzana wrote: How about making regex a built-in feature with this syntax: /regex/ ? I didn't use regex a lot before I started using Ruby. The

Re: Builtin regex (Was: How to complex switch?)

2011-05-13 Thread KennyTM~
On May 13, 11 23:12, Dmitry Olshansky wrote: On 13.05.2011 18:25, Robert Clipsham wrote: On 13/05/2011 05:14, Ary Manzana wrote: How about making regex a built-in feature with this syntax: /regex/ ? I didn't use regex a lot before I started using Ruby. The thing is, in Ruby it's so easy to use

Re: Builtin regex (Was: How to complex switch?)

2011-05-13 Thread Dmitry Olshansky
On 13.05.2011 18:25, Robert Clipsham wrote: On 13/05/2011 05:14, Ary Manzana wrote: How about making regex a built-in feature with this syntax: /regex/ ? I didn't use regex a lot before I started using Ruby. The thing is, in Ruby it's so easy to use regex that I just started using them a lot mo

Re: Builtin regex (Was: How to complex switch?)

2011-05-13 Thread Robert Clipsham
On 13/05/2011 05:14, Ary Manzana wrote: How about making regex a built-in feature with this syntax: /regex/ ? I didn't use regex a lot before I started using Ruby. The thing is, in Ruby it's so easy to use regex that I just started using them a lot more than before. Of course, ruby has built-in

Re: Builtin regex (Was: How to complex switch?)

2011-05-13 Thread Ary Manzana
On 5/13/11 12:10 PM, KennyTM~ wrote: On May 13, 11 12:14, Ary Manzana wrote: On 5/12/11 6:42 PM, KennyTM~ wrote: On May 12, 11 19:13, Matthew Ong wrote: Hi All, Anyway to include this cool feature of switch with D in the near future? Why the obsession with 'switch'? 'if' works fine. swit

Re: Builtin regex (Was: How to complex switch?)

2011-05-12 Thread KennyTM~
On May 13, 11 12:14, Ary Manzana wrote: On 5/12/11 6:42 PM, KennyTM~ wrote: On May 12, 11 19:13, Matthew Ong wrote: Hi All, Anyway to include this cool feature of switch with D in the near future? Why the obsession with 'switch'? 'if' works fine. switch(str){ // regexp case "abc", "def",

Builtin regex (Was: How to complex switch?)

2011-05-12 Thread Ary Manzana
On 5/12/11 6:42 PM, KennyTM~ wrote: On May 12, 11 19:13, Matthew Ong wrote: Hi All, Anyway to include this cool feature of switch with D in the near future? Why the obsession with 'switch'? 'if' works fine. switch(str){ // regexp case "abc", "def", "as+b?": s1(); break; case "za+", "wd?",

Re: How to complex switch?

2011-05-12 Thread bearophile
Matthew Ong: > Anyway to include this cool feature of switch with D in the near future? I think there are no plans in adding a switch as powerful as you ask. The idea of adding pattern matching to D as in functional languages (as seen in Haskell, OCaML or even Scala) was discussed, it's a nice

Re: How to complex switch?

2011-05-12 Thread dennis luehring
Am 12.05.2011 16:33, schrieb Matthew Ong: From what I can see u did not provide any clear answer and hence, I would only discount all your threads as hostile to someone new to D-Programming that is asking sincere and providing some clearly supportable features. If those feature are as what u hav

Re: How to complex switch?

2011-05-12 Thread Timon Gehr
Note that it would in principle be possible to have a library-based solution that provides the functionality you want with the following syntax: import rswitch; // I made that module name up. ... mixin(rswitch(q{ switch(str){ case "abc", "def", "as+b?": if( str == || str == && etc

Re: How to complex switch?

2011-05-12 Thread Michel Fortin
On 2011-05-12 07:13:59 -0400, Matthew Ong said: Anyway to include this cool feature of switch with D in the near future? switch(str){ // regexp case "abc", "def", "as+b?": s1(); break; case "za+", "wd?", "aaa": s2(); break; default: s3(); } The idea is nice. But it break

Re: How to complex switch?

2011-05-12 Thread Matthew Ong
Hi, The over all process perhaps is wrong, I would use a more mature enviroment with huge sets or code sample to build some commonly used routine for myself. And later export them into various different language using process like this. http://xes.sourceforge.net/ The library that I shown so far

Re: How to complex switch?

2011-05-12 Thread Andrei Alexandrescu
On 5/12/11 6:13 AM, Matthew Ong wrote: Hi All, Anyway to include this cool feature of switch with D in the near future? switch(str){ // regexp case "abc", "def", "as+b?": s1(); break; case "za+", "wd?", "aaa": s2(); break; default: s3(); } This is a nice feature, but pro

Re: How to complex switch?

2011-05-12 Thread Matthew Ong
Hi Dennis, >From what I can see u did not provide any clear answer and hence, I would only discount all your threads as hostile to someone new to D-Programming that is asking sincere and providing some clearly supportable features. If those feature are as what u have rapidly shot down. Then, may I

Re: How to complex switch?

2011-05-12 Thread KennyTM~
On May 12, 11 20:04, matthew ong wrote: Hi KennyTM~, Some of the valid reason: 1) Less key stroke Invalid, switch (x = f()) { case x < 0: return -x default: return x } 50 significant characters auto x = f(); if (x < 0) return -x; else return x; 41 significant characters 2) Easi

Re: How to complex switch?

2011-05-12 Thread Timon Gehr
Matthew Ong wrote: > == Quote from dennis luehring (dl.so...@gmx.net)'s article > > Am 12.05.2011 14:58, schrieb Matthew Ong: > > > did you see the string mixin feature before? > > http://www.digitalmars.com/d/2.0/mixin.html > > no outer (parsing) generator needed anymore (with small exceptions) :)

Re: How to complex switch?

2011-05-12 Thread dennis luehring
Am 12.05.2011 15:57, schrieb Matthew Ong: == Quote from dennis luehring (dl.so...@gmx.net)'s article Am 12.05.2011 14:58, schrieb Matthew Ong: did you see the string mixin feature before? http://www.digitalmars.com/d/2.0/mixin.html no outer (parsing) generator needed anymore (with small e

Re: How to complex switch?

2011-05-12 Thread Matthew Ong
== Quote from dennis luehring (dl.so...@gmx.net)'s article > Am 12.05.2011 14:58, schrieb Matthew Ong: > did you see the string mixin feature before? > http://www.digitalmars.com/d/2.0/mixin.html > no outer (parsing) generator needed anymore (with small exceptions) :) I fail to see what is being

Re: How to complex switch?

2011-05-12 Thread dennis luehring
Am 12.05.2011 14:58, schrieb Matthew Ong: Denise, please note that I did not say it could not be done with if-else chain, that is clear but switch makes some logical writing easier in simple/trivial cases, and when i becomes more complex you switch back to inner case ifs > and code generat

Re: How to complex switch?

2011-05-12 Thread Matthew Ong
@dennis luehring -- if (match(str, regex("abc|def|as+b?") && BLUB || BLA ... ) { s1(); }else if (match(str, regex("za+|wd?|aaa")){ ... -- switch(str){

Re: How to complex switch?

2011-05-12 Thread dennis luehring
Am 12.05.2011 14:21, schrieb Matthew Ong: @dennis luehring if (match(str, regex("abc|def|as+b?")) { s1(); }else if (match(str, regex("za+|wd?|aaa")){ // a lot of () and | ... might have missed out one of them s2(); }else{

Re: How to complex switch?

2011-05-12 Thread Matthew Ong
@dennis luehring >just a question - did you thought about that longer then 1 minute? >what real problem does this syntactic sugare solves? I do not think that this is syntactic sugar. Compare this 2 block of code. Which is easier to read? I am not asking the level to be at bash shell script, (tha

Re: How to complex switch?

2011-05-12 Thread Matthew Ong
Sample Code of Bash left out in previous post. -- case $space in [1-6]*) // <<< That if some sort of such logic can be supported in D. Message="All is quiet." ;; [7-8]*) Message="Start thinking about cleaning out some stuff

Re: How to complex switch?

2011-05-12 Thread matthew ong
Hi KennyTM~, Some of the valid reason: 1) Less key stroke 2) Easier code generator to implement 3) Better to read. 4) less worries about braket '{'. 5) In Java, C++ we avoided using switch because it ONLY support const & literal type. Most script base language supports things like this. I

Re: How to complex switch?

2011-05-12 Thread dennis luehring
Am 12.05.2011 13:13, schrieb Matthew Ong: Hi All, just a question - did you thought about that longer then 1 minute? what real problem does this syntactic sugare solves?

Re: How to complex switch?

2011-05-12 Thread KennyTM~
On May 12, 11 19:13, Matthew Ong wrote: Hi All, Anyway to include this cool feature of switch with D in the near future? Why the obsession with 'switch'? 'if' works fine. switch(str){ // regexp case "abc", "def", "as+b?": s1(); break; case "za+", "wd?", "aaa": s2(); bre

How to complex switch?

2011-05-12 Thread Matthew Ong
Hi All, Anyway to include this cool feature of switch with D in the near future? switch(str){ // regexp case "abc", "def", "as+b?": s1(); break; case "za+", "wd?", "aaa": s2(); break; default: s3(); } switch (tag) { default: s3() case 0, 1, 2, 3: s1() case 4, 5, 6, 7: s2() }