Jump to page: 1 2
Thread overview
opIn
Feb 18, 2004
C
Feb 18, 2004
Mik Mifflin
Feb 18, 2004
Manfred Nowak
Feb 18, 2004
davepermen
Feb 19, 2004
Manfred Nowak
Feb 19, 2004
C
Feb 19, 2004
larry cowan
Feb 19, 2004
C
Feb 19, 2004
Manfred Nowak
Feb 19, 2004
Ben Hinkle
Feb 19, 2004
C
Feb 19, 2004
Matthew
Feb 19, 2004
Stewart Gordon
Feb 19, 2004
Matthew
Feb 19, 2004
Luke D
Feb 20, 2004
Matthew
Feb 19, 2004
Ivan Senji
Feb 19, 2004
Vathix
February 18, 2004
Can we get this ? And also add it to arrays ?

char []  x = "a string";

if ( "string" in x ) puts("matched");


C


February 18, 2004
C wrote:

> Can we get this ? And also add it to arrays ?
> 
> char []  x = "a string";
> 
> if ( "string" in x ) puts("matched");
> 
> 
> C

I 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
February 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.
February 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.


February 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


February 19, 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 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
>
>


February 19, 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 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 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
> >
> >
>
>


February 19, 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.
February 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:
>
> > 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.

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?



February 19, 2004
C wrote:

> Can we get this ? And also add it to arrays ?
> 
> char []  x = "a string";
> 
> if ( "string" in x ) puts("matched");
> 
> 
> C
>


I 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
« First   ‹ Prev
1 2