February 09, 2005
> If this becomes part of the spec, is there any good reason why it
shouldn't work
> for other (non-array) types as well, such as ints and doubles?

Yes I think if we have it for arrays it should work for all types, I wonder what trouble ( if any ) this would cause for structs / classes etc ?


Charlie


"Nick" <Nick_member@pathlink.com> wrote in message news:cue2bc$bgo$1@digitaldaemon.com...
> In article <cudsrs$58o$1@digitaldaemon.com>, Ivan Senji says...
> >
> >"Charles" <no@email.com> wrote in message news:cudidc$2sht$1@digitaldaemon.com...
> >> I think getting this for all types would be awesome what do ya'll think
?
> >
> >
> >It works for all array types. I had a strong feeling that it was
documented
> >by now,
> >but can't seem to find it anywhere. And i don't think it is a bug. A long
> >time ago
> >i used this syntax with templates and something didn't work (don't
remember
> >what exactly, something with aliases) and Walter fixed that and didn't
> >mention
> >that this syntax is wrong.
> >
> >It would be nice if it was in the spec.
>
> If this becomes part of the spec, is there any good reason why it
shouldn't work
> for other (non-array) types as well, such as ints and doubles? I can see
that
> structs and classes would be a problem though.
>
> Nick
>
>


February 09, 2005
On Wed, 9 Feb 2005 16:31:54 -0600, Charles <no@email.com> wrote:
>> If this becomes part of the spec, is there any good reason why it
> shouldn't work
>> for other (non-array) types as well, such as ints and doubles?
>
> Yes I think if we have it for arrays it should work for all types, I wonder
> what trouble ( if any ) this would cause for structs / classes etc ?

I think it's workable, after all it's only syntactic sugar.

I can see possible collisions i.e. the class has a member 'foo' and a function 'foo' in this form exists. I believe the current method/function resolution system will pick the class method, this could cause bugs/confusion where the programmer meant the free function.

I'm not sure it's possible to detect it and error without changing the resolution system, which seems unlikely to me.

Regan

> Charlie
>
>
> "Nick" <Nick_member@pathlink.com> wrote in message
> news:cue2bc$bgo$1@digitaldaemon.com...
>> In article <cudsrs$58o$1@digitaldaemon.com>, Ivan Senji says...
>> >
>> >"Charles" <no@email.com> wrote in message
>> >news:cudidc$2sht$1@digitaldaemon.com...
>> >> I think getting this for all types would be awesome what do ya'll  
>> think
> ?
>> >
>> >
>> >It works for all array types. I had a strong feeling that it was
> documented
>> >by now,
>> >but can't seem to find it anywhere. And i don't think it is a bug. A  
>> long
>> >time ago
>> >i used this syntax with templates and something didn't work (don't
> remember
>> >what exactly, something with aliases) and Walter fixed that and didn't
>> >mention
>> >that this syntax is wrong.
>> >
>> >It would be nice if it was in the spec.
>>
>> If this becomes part of the spec, is there any good reason why it
> shouldn't work
>> for other (non-array) types as well, such as ints and doubles? I can see
> that
>> structs and classes would be a problem though.
>>
>> Nick
>>
>>
>
>

February 09, 2005
Ben Hinkle wrote:
>>But in D char[] can use functions as if it were a property.
>>So we can use int ends(char[] str1, char[] str2) like this:
>>str1.ends(".com");
> 
> 
> I don't think that's part of the language spec is it? It's an accident that it works and possibly even considered a bug that Walter hasn't fixed yet. 
> 
> 

Yeah, I wouldn't count on that "feature" either.

_______________________
Carlos Santander Bernal
February 10, 2005
"Martin" <Martin_member@pathlink.com> wrote in message news:cud0n0$28vh$1@digitaldaemon.com...
>I was just thinking, that it would be useful to have:
>
> char []S;
>
> if(S.ends(".com")){....
>
> tha same with .starts .contains.
> I need this quite often, I must say.
>
> What you think?

Whether or not one likes C++, it's hard to deny the wisdom of B.S.'s philosphy that if something can be adequately incorporated in a library, it should not be a language feature.



February 10, 2005
Hi, Martin,

Instead of
> char []S;
> if(S.ends(".com")){....

what about just this:

if( isLike( S, "*.com" ) ) ....
if( isLike( S, "http://*" ) ) ....

Source of isLike below

//|
//| isLike - simple pattern match function for the D
//| Supports '*' (any substring) and '?' (any one char) in patterns
//|
//| Andrew Fedoniouk @ Terra Informatica
//|

bit isLike(char[] text, char[] pattern)
{
 const char AnySubString = '*';
 const char AnyOneChar = '?';

 char *str = text;
 char *str_end = str + text.length;
 char *pat = pattern;
 char *pat_end = pat + pattern.length;

 char *wildcard = null;
 char *str_pos = null;

 while(true)
 {
  if (*pat == AnySubString) {
   wildcard = ++pat;
   str_pos = str;
  }
  else if (str == str_end) {
   return pat == pat_end;
  }
  else if (pat < pat_end && (*pat == *str || *pat == AnyOneChar)) {
   ++str;
   ++pat;
  }
  else if (wildcard) {
   str = ++str_pos;
   pat = wildcard;
  }
  else {
   return false;
  }
 }
}


February 10, 2005
//|
//| like - simple pattern match function for the D
//| Supports '*' (any substring) and '?' (any one char) in patterns
//|
//| Andrew Fedoniouk @ Terra Informatica
//|

bit like(char[] text, char[] pattern)
{
    const char AnySubString = '*';
    const char AnyOneChar = '?';

    char *str = text;
    char *str_end = str + text.length;
    char *pat = pattern;
    char *pat_end = pat + pattern.length;

    char *wildcard = null;
    char *str_pos = null;

    while(true)
    {
        if (*pat == AnySubString) {
            wildcard = ++pat;
            str_pos = str;
        } else if (str == str_end) {
            return pat == pat_end;
        } else if (pat < pat_end && (*pat == *str || *pat == AnyOneChar)) {
            ++str;
            ++pat;
        } else if (wildcard) {
            str = ++str_pos;
            pat = wildcard;
        } else {
            return false;
        }
    }
}

unittest
{
     debug(string) printf("std.string.like.unittest\n");
     assert(like("foobar", "foo*"));
     assert(like("foobar", "*bar"));
     assert( !like("", "foo*"));
     assert( !like("", "*bar"));
     assert( !like("", "?"));
     assert( like("f", "?"));
     assert( like("f", "*"));
     assert( like("foo", "?oo"));
     assert( !like("foobar", "?oo"));
     assert( like("foobar", "?oo*"));
     assert( like("foobar", "*oo*b*"));
     assert( like("foobar", "*oo*ar"));
     assert( like("terrainformatica.com", "*.com"));
}



February 10, 2005
"Carlos Santander B." <csantander619@gmail.com> wrote in message news:cue6g8$g43$2@digitaldaemon.com...
> Ben Hinkle wrote:
> >>But in D char[] can use functions as if it were a property.
> >>So we can use int ends(char[] str1, char[] str2) like this:
> >>str1.ends(".com");
> >
> >
> > I don't think that's part of the language spec is it? It's an accident
that
> > it works and possibly even considered a bug that Walter hasn't fixed
yet.
> >
> >
>
> Yeah, I wouldn't count on that "feature" either.
>

Walter please reply that this IS a feature and not a bug.
And if it is a bug please don't remove it and add it to the spec.

:)

> _______________________
> Carlos Santander Bernal


1 2
Next ›   Last »