digitalmars.D.learn - It there a way to get this to compile?
- WhatMeWorry (19/19) Sep 09 2019 Is this even possible?
- Adam D. Ruppe (12/13) Sep 09 2019 what are you trying to do?
- WhatMeWorry (6/19) Sep 09 2019 Oops. I'm trying to build up a complex formatting string of
- a11e99z (5/25) Sep 09 2019 NB
- =?UTF-8?Q?Ali_=c3=87ehreli?= (8/18) Sep 09 2019 Those are fine.
- =?UTF-8?Q?Ali_=c3=87ehreli?= (5/8) Sep 09 2019 Attempting to correct myself: I think only declarations are allowed at=2...
Is this even possible? klondike.d(155): Error: no identifier for declarator c klondike.d(155): Error: declaration expected, not = struct FoundationPile { Card[] up; // all cards are face up on the Foundation } FoundationPile[4] foundations; static if(true) { int r = 2; int c = 40; static foreach(i ; foundations) { immutable string brackets = "\033[" ~ to!string(r) ~ ";" ~ to!string(c) ~ "H"; c = c + 10; // line 155 } }
Sep 09 2019
On Monday, 9 September 2019 at 19:08:17 UTC, WhatMeWorry wrote:Is this even possible?what are you trying to do? if c is static, it just needs to be initialized by a helper function, like int helper() { int c = 60; foreach(f; foundations) c += 10; return c; } static int c = helper(); // it initializes based on teh function now
Sep 09 2019
On Monday, 9 September 2019 at 19:12:34 UTC, Adam D. Ruppe wrote:On Monday, 9 September 2019 at 19:08:17 UTC, WhatMeWorry wrote:Oops. I'm trying to build up a complex formatting string of Console Virtual Terminal Sequences. Should be ~= or is that =~. I never can remember. immutable string brackets ~= "\033[" ~ to!string(r) ~ ";" ~ to!string(c) ~ "H";Is this even possible?what are you trying to do? if c is static, it just needs to be initialized by a helper function, like int helper() { int c = 60; foreach(f; foundations) c += 10; return c; } static int c = helper(); // it initializes based on teh function now
Sep 09 2019
On Monday, 9 September 2019 at 19:08:17 UTC, WhatMeWorry wrote:struct FoundationPile { Card[] up; // all cards are face up on the Foundation } FoundationPile[4] foundations; static if(true) { int r = 2; int c = 40; static foreach(i ; foundations) { immutable string brackets = "\033[" ~ to!string(r) ~ ";" ~ to!string(c) ~ "H"; c = c + 10; // line 155 } }NB dont use name "i" for foreach/ranges, foreach can be used with index too, use "el" as "element" or "it" as "iterator" or just "something"static if(true) { enum r = 2, c = 40; // bad names too static foreach( idx, el; foundations) { immutable string brackets = "\033[" ~ to!string(r) ~ ";" ~ to!string(c + idx*10) ~ "H"; } }
Sep 09 2019
On 09/09/2019 12:08 PM, WhatMeWorry wrote:Is this even possible?No because there can't be expressions at module scope.static if(true) { int r = 2; int c = 40;Those are fine.static foreach(i ; foundations) { immutable string brackets = "\033[" ~ to!string(r) ~ ";" ~ to!string(c) ~ "H";That's fine as well.c = c + 10; // line 155That expression cannot appear at module scope. (In case it's not clear, 'static if' and 'static foreach' disappear after a stage of compilation and their contents are left behind at module scope.) Ali
Sep 09 2019
On 09/09/2019 01:59 PM, Ali =C3=87ehreli wrote:On 09/09/2019 12:08 PM, WhatMeWorry wrote: > Is this even possible? No because there can't be expressions at module scope.Attempting to correct myself: I think only declarations are allowed at=20 module scope. Non-compile-time statements like for, switch, etc. cannot=20 appear at module scope either. Ali
Sep 09 2019