Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
September 25, 2002 'in' would be nice for normal arrays, too... | ||||
---|---|---|---|---|
| ||||
I'm running across places in my code where I want to test an array for the existence of a certain value: Foo[] array; Foo value; // need to check: is value in array? if(value in array) // this doesn't work, so far { .. } Right now, I'm wavering. In one place, I created an associative array of bits, and then I get the "keys" property to get the real values: bit[Foo] array; Foo value; if(value in array) // this works { .. } In another, I'm thinking of writing an actual search function. Perhaps a wishlist item, I suppose... |
September 26, 2002 Re: 'in' would be nice for normal arrays, too... | ||||
---|---|---|---|---|
| ||||
Posted in reply to Russell Lewis | Russell Lewis wrote:
> I'm running across places in my code where I want to test an array for the existence of a certain value:
>
> Foo[] array;
> Foo value;
> // need to check: is value in array?
> if(value in array) // this doesn't work, so far
> {
> ..
> }
I agree, this should be valid, even though the implementation will just be a linear search. Marked in TODO.
|
September 29, 2002 Re: 'in' would be nice for normal arrays, too... | ||||
---|---|---|---|---|
| ||||
Posted in reply to Russell Lewis | I think this is a great and natural idea. Thanks! "Russell Lewis" <spamhole-2001-07-16@deming-os.org> wrote in message news:3D91E904.2080409@deming-os.org... > I'm running across places in my code where I want to test an array for the existence of a certain value: > > Foo[] array; > Foo value; > // need to check: is value in array? > if(value in array) // this doesn't work, so far > { > .. > } > > Right now, I'm wavering. In one place, I created an associative array > of bits, and then I get the "keys" property to get the real values: > bit[Foo] array; > Foo value; > if(value in array) // this works > { > .. > } > > In another, I'm thinking of writing an actual search function. > > Perhaps a wishlist item, I suppose... > |
October 10, 2002 Re: 'in' would be nice for normal arrays, too... | ||||
---|---|---|---|---|
| ||||
Posted in reply to Russell Lewis | > I'm running across places in my code where I want to test an array for the existence of a certain value:
>
> Foo[] array;
> Foo value;
> // need to check: is value in array?
> if(value in array) // this doesn't work, so far
> {
> ..
> }
>
> Right now, I'm wavering. In one place, I created an associative array
> of bits, and then I get the "keys" property to get the real values:
> bit[Foo] array;
> Foo value;
> if(value in array) // this works
> {
> ..
> }
>
> In another, I'm thinking of writing an actual search function.
>
> Perhaps a wishlist item, I suppose...
If it were valid, the "in" sintax wouldn't need to be valid for
associative arrays, since you would be able to write "key in assArray.keys;"
This should be optimized by the compiler and can decrease the language
complexity (and maybe the compiler's one), though increasing the typing.
Just thoughts.
|
October 11, 2002 Re: 'in' would be nice for normal arrays, too... | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dario | Dario wrote: > > I'm running across places in my code where I want to test an array for the existence of a certain value: > > > > Foo[] array; > > Foo value; > > // need to check: is value in array? > > if(value in array) // this doesn't work, so far > > { > > .. > > } > > > > Right now, I'm wavering. In one place, I created an associative array > > of bits, and then I get the "keys" property to get the real values: > > bit[Foo] array; > > Foo value; > > if(value in array) // this works > > { > > .. > > } > > > > In another, I'm thinking of writing an actual search function. > > > > Perhaps a wishlist item, I suppose... > > If it were valid, the "in" sintax wouldn't need to be valid for > associative arrays, since you would be able to write "key in assArray.keys;" > This should be optimized by the compiler and can decrease the language > complexity (and maybe the compiler's one), though increasing the typing. > Just thoughts. This actually might be a very good idea, since a programmer might want to know if a value is "in keys" or "in values". I would support doing this. Disallow the "in" property for associative arrays, but make an explicit suggestion that the compiler optimize for "value in assocArray.keys" and "value in assocArray.values". -- The Villagers are Online! http://villagersonline.com .[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ] .[ (a version.of(English).(precise.more)) is(possible) ] ?[ you want.to(help(develop(it))) ] |
Copyright © 1999-2021 by the D Language Foundation