digitalmars.D.learn - Array is already defined
- Vino (16/16) Jan 05 2018 Hi All,
- Jonathan M Davis (5/21) Jan 05 2018 static foreach does not create a new scope (if it did, it wouldn't work ...
- Vino (15/42) Jan 05 2018 Hi Jonathan,
- Steven Schveighoffer (4/47) Jan 05 2018 }
- Vino (19/72) Jan 05 2018 Hi Steve,
- Steven Schveighoffer (4/21) Jan 05 2018 That's because writeln is outside the loop that defines Datacol.
- Vino (13/36) Jan 05 2018 Hi Steve,
- H. S. Teoh (17/21) Jan 05 2018 Try this:
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
Jan 05 2018
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.Bstatic 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
Jan 05 2018
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 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.BHi 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.Bstatic 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
Jan 05 2018
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 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) {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.Bstatic 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 Davistypeof(read()[i]) Datacol; Datacol.insertBack(sort(read[i].dup[]).uniq); foreach(k; read[i]) { Keycol.insertBack(Datacol[].countUntil(k));}}} writeln (Datacol[], Keycol[]); }-Steve
Jan 05 2018
On Friday, 5 January 2018 at 16:07:49 UTC, Steven Schveighoffer wrote:On 1/5/18 10:56 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[]); } From, Vino.BOn 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 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) {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.Bstatic 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 Davistypeof(read()[i]) Datacol; Datacol.insertBack(sort(read[i].dup[]).uniq); foreach(k; read[i]) { Keycol.insertBack(Datacol[].countUntil(k));}}} writeln (Datacol[], Keycol[]); }-Steve
Jan 05 2018
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
Jan 05 2018
On Friday, 5 January 2018 at 16:55:50 UTC, Steven Schveighoffer wrote:On 1/5/18 11:39 AM, Vino wrote: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.BHi 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
Jan 05 2018
On Fri, Jan 05, 2018 at 03:56:30PM +0000, 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.
Jan 05 2018