Re: Array is already defined

2018-01-05 Thread Vino via Digitalmars-d-learn
On Friday, 5 January 2018 at 16:55:50 UTC, Steven Schveighoffer 
wrote:

On 1/5/18 11:39 AM, Vino wrote:


Hi Steve,

  if we add the braces we are getting the Error: undefined 
identifier Datacol


void main () {
Array!int Keycol;
static foreach(i; 0 .. 3) {
 {
     typeof(read()[i]) Datacol;
     Datacol.insertBack(sort(read[i].dup[]).uniq);
     foreach(k; read[i]) { 
Keycol.insertBack(Datacol[].countUntil(k));}

 }
}
 writeln (Datacol[], Keycol[]);
}


That's because writeln is outside the loop that defines Datacol.

Without knowing what you are trying to do, it's hard to further 
help.


-Steve


Hi Steve,

 Thank you very much, was able to resolve the issue after adding 
the writeln within the braces, I am trying to implement a data 
dictionary compressing using D, and had 2 issue and this is one 
of the issue, and the other issue is detailed in the post "Error: 
variable i cannot be read at compile time", which contains the 
details of this program, if possible can you please help on on 
the other issue in the post "Error: variable i cannot be read at 
compile time".


From,
Vino.B




Re: Array is already defined

2018-01-05 Thread Steven Schveighoffer via Digitalmars-d-learn

On 1/5/18 11:39 AM, Vino wrote:


Hi Steve,

  if we add the braces we are getting the Error: undefined identifier 
Datacol


void main () {
Array!int Keycol;
static foreach(i; 0 .. 3) {
 {
     typeof(read()[i]) Datacol;
     Datacol.insertBack(sort(read[i].dup[]).uniq);
     foreach(k; read[i]) { Keycol.insertBack(Datacol[].countUntil(k));}
 }
}
 writeln (Datacol[], Keycol[]);
}


That's because writeln is outside the loop that defines Datacol.

Without knowing what you are trying to do, it's hard to further help.

-Steve


Re: Array is already defined

2018-01-05 Thread Vino via Digitalmars-d-learn
On Friday, 5 January 2018 at 16:07:49 UTC, Steven Schveighoffer 
wrote:

On 1/5/18 10:56 AM, Vino wrote:
On Friday, 5 January 2018 at 15:28:58 UTC, Jonathan M Davis 
wrote:
On Friday, January 05, 2018 15:22:49 Vino via 
Digitalmars-d-learn wrote:

Hi All,

  Request your help on how to unset or delete an array, in 
the

below example, we get an error "Common  is already defined".

Auto fn1 () {
Array!string Text;
Array!string Number;
return tuple(Text, Number);
}

Void main () {
static foreach(i; 0 .. 2) {
typeof(fn1()[i]) Common;
writeln(Common[]);
Common.delete or Common.Unset // Something similar like this
}

From,
Vino.B


static foreach does not create a new scope (if it did, it 
wouldn't work very well at module or class/struct scope). If 
you declare any variables inside a static foreach, give it an 
extra set of braces.


- Jonathan m Davis


Hi Jonathan,

  Sorry , not able to get you, can you please point our as to 
where we need to added the braces in the below example.


void main () {
Array!int Keycol;
static foreach(i; 0 .. 3) {

{

typeof(read()[i]) Datacol;
Datacol.insertBack(sort(read[i].dup[]).uniq);
foreach(k; read[i]) { 
Keycol.insertBack(Datacol[].countUntil(k));}

}

}
writeln (Datacol[], Keycol[]);
}



-Steve


Hi Steve,

 if we add the braces we are getting the Error: undefined 
identifier Datacol


void main () {
Array!int Keycol;
static foreach(i; 0 .. 3) {
{
typeof(read()[i]) Datacol;
Datacol.insertBack(sort(read[i].dup[]).uniq);
		foreach(k; read[i]) { 
Keycol.insertBack(Datacol[].countUntil(k));}

}
}
writeln (Datacol[], Keycol[]);
}

From,
Vino.B


Re: Array is already defined

2018-01-05 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jan 05, 2018 at 03:56:30PM +, Vino via Digitalmars-d-learn wrote:
[...]
> Hi Jonathan,
> 
>  Sorry , not able to get you, can you please point our as to where we
>  need to added the braces in the below example.

Try this:

void main () {
Array!int Keycol;
static foreach(i; 0 .. 3) {{
typeof(read()[i]) Datacol;
Datacol.insertBack(sort(read[i].dup[]).uniq);
foreach(k; read[i]) {
Keycol.insertBack(Datacol[].countUntil(k));
}
}}
writeln (Datacol[], Keycol[]);
}


T

-- 
Tech-savvy: euphemism for nerdy.


Re: Array is already defined

2018-01-05 Thread Steven Schveighoffer via Digitalmars-d-learn

On 1/5/18 10:56 AM, Vino wrote:

On Friday, 5 January 2018 at 15:28:58 UTC, Jonathan M Davis wrote:

On Friday, January 05, 2018 15:22:49 Vino via Digitalmars-d-learn wrote:

Hi All,

  Request your help on how to unset or delete an array, in the
below example, we get an error "Common  is already defined".

Auto fn1 () {
Array!string Text;
Array!string Number;
return tuple(Text, Number);
}

Void main () {
static foreach(i; 0 .. 2) {
typeof(fn1()[i]) Common;
writeln(Common[]);
Common.delete or Common.Unset // Something similar like this
}

From,
Vino.B


static foreach does not create a new scope (if it did, it wouldn't 
work very well at module or class/struct scope). If you declare any 
variables inside a static foreach, give it an extra set of braces.


- Jonathan m Davis


Hi Jonathan,

  Sorry , not able to get you, can you please point our as to where we 
need to added the braces in the below example.


void main () {
Array!int Keycol;
static foreach(i; 0 .. 3) {

{

typeof(read()[i]) Datacol;
Datacol.insertBack(sort(read[i].dup[]).uniq);
foreach(k; read[i]) { Keycol.insertBack(Datacol[].countUntil(k));} 

}

}
writeln (Datacol[], Keycol[]);
}



-Steve



Re: Array is already defined

2018-01-05 Thread Vino via Digitalmars-d-learn

On Friday, 5 January 2018 at 15:28:58 UTC, Jonathan M Davis wrote:
On Friday, January 05, 2018 15:22:49 Vino via 
Digitalmars-d-learn wrote:

Hi All,

  Request your help on how to unset or delete an array, in the
below example, we get an error "Common  is already defined".

Auto fn1 () {
Array!string Text;
Array!string Number;
return tuple(Text, Number);
}

Void main () {
static foreach(i; 0 .. 2) {
typeof(fn1()[i]) Common;
writeln(Common[]);
Common.delete or Common.Unset // Something similar like this
}

From,
Vino.B


static foreach does not create a new scope (if it did, it 
wouldn't work very well at module or class/struct scope). If 
you declare any variables inside a static foreach, give it an 
extra set of braces.


- Jonathan m Davis


Hi Jonathan,

 Sorry , not able to get you, can you please point our as to 
where we need to added the braces in the below example.


void main () {
Array!int Keycol;
static foreach(i; 0 .. 3) {
typeof(read()[i]) Datacol;
Datacol.insertBack(sort(read[i].dup[]).uniq);
foreach(k; read[i]) { 
Keycol.insertBack(Datacol[].countUntil(k));} }

writeln (Datacol[], Keycol[]);
}

From,
Vino.B


Re: Array is already defined

2018-01-05 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, January 05, 2018 15:22:49 Vino via Digitalmars-d-learn wrote:
> Hi All,
>
>   Request your help on how to unset or delete an array, in the
> below example, we get an error "Common  is already defined".
>
> Auto fn1 () {
> Array!string Text;
> Array!string Number;
> return tuple(Text, Number);
> }
>
> Void main () {
> static foreach(i; 0 .. 2) {
> typeof(fn1()[i]) Common;
> writeln(Common[]);
> Common.delete or Common.Unset // Something similar like this
> }
>
> From,
> Vino.B

static foreach does not create a new scope (if it did, it wouldn't work very
well at module or class/struct scope). If you declare any variables inside a
static foreach, give it an extra set of braces.

- Jonathan m Davis