D - opIn
- C (4/4) Feb 18 2004 Can we get this ? And also add it to arrays ?
- Mik Mifflin (12/20) Feb 18 2004 I think that particular example would be best implemented as a string se...
- Manfred Nowak (5/8) Feb 18 2004 What do you have against the regular expression package? And if you want
- davepermen (6/14) Feb 18 2004 i never got the regular expression packages to do what i want. they are ...
- Manfred Nowak (7/8) Feb 19 2004 [...]
- C (9/17) Feb 19 2004 Ugh , that was probably the worst example I could have written. I just ...
- larry cowan (15/36) Feb 19 2004 Maybe I'm too old-fashioned, but IMHOFO a lauguage should choose it's pr...
- C (35/81) Feb 19 2004 I am must be horrible at explaining, or there is a misunderstanding
- Manfred Nowak (5/6) Feb 19 2004 [...]
-
Ben Hinkle
(14/14)
Feb 18 2004
"C"
wrote in message news:c10g8o$307o$1@digitaldaemon... - C (7/21) Feb 18 2004 Your right that was a bad example. Supposing we had an array of objects...
- Matthew (17/44) Feb 18 2004 I heartily agree on "in". In fact I think the language is broken without...
- Stewart Gordon (13/18) Feb 19 2004 That would be semantics bending. The role of 'in' is to determine
- Matthew (4/15) Feb 19 2004 Why so? What's wrong with 'in' meaning just an element exists within a
- Luke D (11/28) Feb 19 2004 The use of in would be entirely ambiguous though. If you'd use in on an
- Matthew (12/43) Feb 19 2004 array.
- Ivan Senji (21/39) Feb 19 2004 i don't agree
- Vathix (9/17) Feb 19 2004 I would like it to return a boolean if a particular "sub item" is within...
Can we get this ? And also add it to arrays ? char [] x = "a string"; if ( "string" in x ) puts("matched"); C
Feb 18 2004
C wrote:Can we get this ? And also add it to arrays ? char [] x = "a string"; if ( "string" in x ) puts("matched"); CI think that particular example would be best implemented as a string search function. However, it would make more sense to have something like this: char[] str = "some string"; if ('t' in str) { ... } static int[3] arr = [10, 20, 30]; if (20 in arr) { ... } Though, perhaps that use would be better off as a function as well? Is the reason the in operator exists in associative array because the lookup is cheaper than a brute force iteration/compare? -- - Mik Mifflin
Feb 18 2004
C wrote:Can we get this ? And also add it to arrays ? char [] x = "a string"; if ( "string" in x ) puts("matched");What do you have against the regular expression package? And if you want some of the regular expression techniques integrated into the language why not all of them? So long.
Feb 18 2004
i never got the regular expression packages to do what i want. they are not easy to use, the regular expressions.. could you provide a counter-example, showing how this would be done with re's ? would be possibly very helpful.. "Manfred Nowak" <svv1999 hotmail.com> schrieb im Newsbeitrag news:c10pkh$ejl$1 digitaldaemon.com...C wrote:Can we get this ? And also add it to arrays ? char [] x = "a string"; if ( "string" in x ) puts("matched");What do you have against the regular expression package? And if you want some of the regular expression techniques integrated into the language why not all of them? So long.
Feb 18 2004
davepermen wrote: [...]how this would be done with re's ?[...] if((new RegExp("string","")).test("a string")) puts("matched"); I would like that Walter would have provided some syntactical sugar to omit an empty attributes list. So long.
Feb 19 2004
Ugh , that was probably the worst example I could have written. I just mean if ( item in collection ) {} Ignore the example ( I would probably just use if ( find( str,"str") != -1 ) for that ). Charlie However in my own defenese if opIn was overloadable we could also do if ( subcollection in largercollection ) also :) ( not for arrays ) "Manfred Nowak" <svv1999 hotmail.com> wrote in message news:c12ck7$3e2$1 digitaldaemon.com...davepermen wrote: [...]how this would be done with re's ?[...] if((new RegExp("string","")).test("a string")) puts("matched"); I would like that Walter would have provided some syntactical sugar to omit an empty attributes list. So long.
Feb 19 2004
Maybe I'm too old-fashioned, but IMHOFO a lauguage should choose it's primitives well, support them well, (within the compiler) and leave the other fancies to libraries. Sorry, but I don't think "collections" should be internalized to the compiler, and its easy enough to write a function, a template, or a class to do what you want. Write it, tune it the way you want, and use it as needed. And about subcollections within (or not) collections, overlapping (or not) with other subcollections, ad infinitum - I think not - have you ever heard of loops? - or were you thinking that the compiler should read your mind and know that this collection should be hashed, and in such a way that subcollection1 and subcollection2 can easily be subsetted, and have everything done in the most efficient way (presuming that this is not data dependent - or maybe it should adjust for that dynamically)? -larry In article <c12ng3$nch$1 digitaldaemon.com>, C says...Ugh , that was probably the worst example I could have written. I just mean if ( item in collection ) {} Ignore the example ( I would probably just use if ( find( str,"str") != -1 ) for that ). Charlie However in my own defenese if opIn was overloadable we could also do if ( subcollection in largercollection ) also :) ( not for arrays ) "Manfred Nowak" <svv1999 hotmail.com> wrote in message news:c12ck7$3e2$1 digitaldaemon.com...davepermen wrote: [...]how this would be done with re's ?[...] if((new RegExp("string","")).test("a string")) puts("matched"); I would like that Walter would have provided some syntactical sugar to omit an empty attributes list. So long.
Feb 19 2004
I am must be horrible at explaining, or there is a misunderstanding somewhere. I want an operator for a class , for your own collections. struct Deuque(T) { T[] collection; bit opIn(T t ) { /* enumerate through collection, return true if found*/ } } bit opIn(T[] t ) { /* return true if all of t is in collection */ } } } Deuque!(int) d; /* fill d */ int userInput = 0; /* get var from user */ if ( userInput in d ) { doFoo(); } Why did u think I was talking about primitives ? For D at least doesnt an operator imply a class / struct / template ? I dont want the compiler to do anything more than translate the 'in' operator to the corresponding member function. Charles. "larry cowan" <larry_member pathlink.com> wrote in message news:c12p6j$qh8$1 digitaldaemon.com...Maybe I'm too old-fashioned, but IMHOFO a lauguage should choose it'sprimitiveswell, support them well, (within the compiler) and leave the other fanciestolibraries. Sorry, but I don't think "collections" should be internalized to thecompiler,and its easy enough to write a function, a template, or a class to do whatyouwant. Write it, tune it the way you want, and use it as needed. And about subcollections within (or not) collections, overlapping (or not)withother subcollections, ad infinitum - I think not - have you ever heard ofloops?- or were you thinking that the compiler should read your mind and knowthatthis collection should be hashed, and in such a way that subcollection1andsubcollection2 can easily be subsetted, and have everything done in themostefficient way (presuming that this is not data dependent - or maybe itshouldadjust for that dynamically)? -larry In article <c12ng3$nch$1 digitaldaemon.com>, C says...meanUgh , that was probably the worst example I could have written. I just!= -1 )if ( item in collection ) {} Ignore the example ( I would probably just use if ( find( str,"str")for that ). Charlie However in my own defenese if opIn was overloadable we could also do if ( subcollection in largercollection ) also :) ( not for arrays ) "Manfred Nowak" <svv1999 hotmail.com> wrote in message news:c12ck7$3e2$1 digitaldaemon.com...davepermen wrote: [...]how this would be done with re's ?[...] if((new RegExp("string","")).test("a string")) puts("matched"); I would like that Walter would have provided some syntactical sugar to omit an empty attributes list. So long.
Feb 19 2004
C wrote: [...]Why did u think I was talking about primitives ?[...] Ahh, I've got it. Surely I am with you to be able to overload `in'. So long.
Feb 19 2004
"C" <dont respond.com> wrote in message news:c10g8o$307o$1 digitaldaemon.com... | Can we get this ? And also add it to arrays ? | | char [] x = "a string"; | | if ( "string" in x ) puts("matched"); the function string.find(char[] s, char[] sub) will also return the index of the match (which is common information to want when you have a match). One nice extension to some of the string functions would be to templatize them: int find(T[] s, T[] sub) Since it involves templates and containers/arrays that would best be part of DTL. -Ben
Feb 18 2004
Your right that was a bad example. Supposing we had an array of objects ? I guess we have foreach which is really smooth , I just really like the look and ease of 'in'. C "Ben Hinkle" <bhinkle4 juno.com> wrote in message news:c1175t$13l8$1 digitaldaemon.com..."C" <dont respond.com> wrote in messagenews:c10g8o$307o$1 digitaldaemon.com...| Can we get this ? And also add it to arrays ? | | char [] x = "a string"; | | if ( "string" in x ) puts("matched"); the function string.find(char[] s, char[] sub) will also return the index of the match (which is common information to want when you have a match). One nice extension to some of the string functions would be to templatize them: int find(T[] s, T[] sub) Since it involves templates and containers/arrays that would best be part of DTL. -Ben
Feb 18 2004
I heartily agree on "in". In fact I think the language is broken without it. But your example was not an example of in, since you were not searching for an item (char) in your collection (string). I *strongly* disagree on that use of "in". But char [] x = "a string"; if ( ' ' in x ) { puts("matched"); } is a perfectly reasonable use of "in". "C" <dont respond.com> wrote in message news:c118ae$15dr$1 digitaldaemon.com...Your right that was a bad example. Supposing we had an array of objects ? I guess we have foreach which is really smooth , I just really like thelookand ease of 'in'. C "Ben Hinkle" <bhinkle4 juno.com> wrote in message news:c1175t$13l8$1 digitaldaemon.com...index"C" <dont respond.com> wrote in messagenews:c10g8o$307o$1 digitaldaemon.com...| Can we get this ? And also add it to arrays ? | | char [] x = "a string"; | | if ( "string" in x ) puts("matched"); the function string.find(char[] s, char[] sub) will also return thematch).of the match (which is common information to want when you have atemplatizeOne nice extension to some of the string functions would be tothem: int find(T[] s, T[] sub) Since it involves templates and containers/arrays that would best be part of DTL. -Ben
Feb 18 2004
While it was 2/18/04 10:08 PM throughout the UK, C sprinkled little black dots on a white screen, and they fell thus:Can we get this ? And also add it to arrays ? char [] x = "a string"; if ( "string" in x ) puts("matched");That would be semantics bending. The role of 'in' is to determine whether a key exists in an associative array. If it's ever defined on normal arrays, it would have to mean the given index being within the array's bounds. We have '~' for string concatenation, to avoid confusingly overloading '+'. Surely we shouldn't be confusingly overloading 'in' either? Stewart. -- My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit.
Feb 19 2004
"Stewart Gordon" <smjg_1998 yahoo.com> wrote in message news:c12787$2rkt$1 digitaldaemon.com...While it was 2/18/04 10:08 PM throughout the UK, C sprinkled little black dots on a white screen, and they fell thus:Why so? What's wrong with 'in' meaning just an element exists within a collection? Why must it ape the semantics of the associative arrays?Can we get this ? And also add it to arrays ? char [] x = "a string"; if ( "string" in x ) puts("matched");That would be semantics bending. The role of 'in' is to determine whether a key exists in an associative array. If it's ever defined on normal arrays, it would have to mean the given index being within the array's bounds.
Feb 19 2004
In article <c129oq$2vmq$1 digitaldaemon.com>, Matthew says..."Stewart Gordon" <smjg_1998 yahoo.com> wrote in message news:c12787$2rkt$1 digitaldaemon.com...The use of in would be entirely ambiguous though. If you'd use in on an associative array, right now it'll return a bool if the key exists in the array. If it would be extended to also say whether a value exists in a collection/array, what would it mean if the operator was used on an associative array? IMO, the in operator should be overloadable to make classes that mimic associative arrays, and if an operator is really needed to check whether a value exists in an array, it would need to be a new operator (though... it might be a bit confusing since when people see in, they'll think it means to check for value if they haven't used that part of the language before...)While it was 2/18/04 10:08 PM throughout the UK, C sprinkled little black dots on a white screen, and they fell thus:Why so? What's wrong with 'in' meaning just an element exists within a collection? Why must it ape the semantics of the associative arrays?Can we get this ? And also add it to arrays ? char [] x = "a string"; if ( "string" in x ) puts("matched");That would be semantics bending. The role of 'in' is to determine whether a key exists in an associative array. If it's ever defined on normal arrays, it would have to mean the given index being within the array's bounds.
Feb 19 2004
"Luke D" <Luke_member pathlink.com> wrote in message news:c13bf6$1s53$1 digitaldaemon.com...In article <c129oq$2vmq$1 digitaldaemon.com>, Matthew says...array."Stewart Gordon" <smjg_1998 yahoo.com> wrote in message news:c12787$2rkt$1 digitaldaemon.com...The use of in would be entirely ambiguous though. If you'd use in on an associative array, right now it'll return a bool if the key exists in theWhile it was 2/18/04 10:08 PM throughout the UK, C sprinkled little black dots on a white screen, and they fell thus:Why so? What's wrong with 'in' meaning just an element exists within a collection? Why must it ape the semantics of the associative arrays?Can we get this ? And also add it to arrays ? char [] x = "a string"; if ( "string" in x ) puts("matched");That would be semantics bending. The role of 'in' is to determine whether a key exists in an associative array. If it's ever defined on normal arrays, it would have to mean the given index being within the array's bounds.If it would be extended to also say whether a value exists in a collection/array, what would it mean if the operator was used on anassociativearray?The same thing as it does now. I don't see the problem personally, but then I've always looked at maps/assoc-arrays as having the keys being the important thing. Nonetheless, I understand your point. It needs further thought. How do other languages deal with this?IMO, the in operator should be overloadable to make classes that mimic associative arrays, and if an operator is really needed to check whether avalueexists in an array, it would need to be a new operator (though... it mightbe abit confusing since when people see in, they'll think it means to checkforvalue if they haven't used that part of the language before...)
Feb 19 2004
"Stewart Gordon" <smjg_1998 yahoo.com> wrote in message news:c12787$2rkt$1 digitaldaemon.com...While it was 2/18/04 10:08 PM throughout the UK, C sprinkled little black dots on a white screen, and they fell thus:i don't agree I often wan't to write something like this: int[] numbers; int x; if(x in numbers) { //do something } but then i remember that there is no in for arrays and have to do it like this foreach(int i; numbers) { if(i == x) { //do something break; } } Which is a lot more typing when the types are more complex than int[]Can we get this ? And also add it to arrays ? char [] x = "a string"; if ( "string" in x ) puts("matched");That would be semantics bending. The role of 'in' is to determine whether a key exists in an associative array. If it's ever defined on normal arrays, it would have to mean the given index being within the array's bounds.We have '~' for string concatenation, to avoid confusingly overloading '+'. Surely we shouldn't be confusingly overloading 'in' either? Stewart. -- My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit.
Feb 19 2004
C wrote:Can we get this ? And also add it to arrays ? char [] x = "a string"; if ( "string" in x ) puts("matched"); CI would like it to return a boolean if a particular "sub item" is within the object. If it's either a wchar in a int[wchar], a char in a char[], or a FooItem in a Foo (custom)... but I don't really think finding "string" in "a string" is good. -- Christopher E. Miller www.dprogramming.com irc.dprogramming.com #D
Feb 19 2004