digitalmars.D.learn - Why doesn't this have a length?
- Magnus Lie Hetland (14/14) Mar 12 2012 In a template class (with State and Input as template parameters), I
- bearophile (5/6) Mar 12 2012 It looks legal. As usual I suggest to minimize the code, and show
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (5/11) Mar 12 2012 Let's please also see the exact error message. "an error message that
- Andrej Mitrovic (15/18) Mar 12 2012 He probably means something like this:
- =?utf-8?Q?Simen_Kj=C3=A6r=C3=A5s?= (16/34) Mar 12 2012 =
- Magnus Lie Hetland (10/14) Mar 13 2012 Indeed. Would've thought const AA keys would be reasonable. (In Python
- H. S. Teoh (16/22) Mar 13 2012 [...]
- Magnus Lie Hetland (5/10) Mar 13 2012 Seconded, whole-heartedly.
In a template class (with State and Input as template parameters), I have the following (private) member: State[][Tuple!(const(State), const(Input))] transitions; It works well enough, but for some reason I can't access its length attribute...? (If I define other simpler, similar private attributes, such as uint[uint], I can access their length in the same location where transition.length fails.) I get an error message that seems to indicate that DMD is looking for a global identifier. I've tried instantiating with different types, e.g., uint. Am I doing something illegal?-) -- Magnus Lie Hetland http://hetland.org
Mar 12 2012
Magnus Lie Hetland:Am I doing something illegal?-)It looks legal. As usual I suggest to minimize the code, and show us the reduced case that shows the problem :-) Bye, bearophile
Mar 12 2012
On 03/12/2012 08:59 AM, bearophile wrote:Magnus Lie Hetland:Let's please also see the exact error message. "an error message that seems to indicate that DMD is looking for a global identifier" is not clear to mortals like myself. :) AliAm I doing something illegal?-)It looks legal. As usual I suggest to minimize the code, and show us the reduced case that shows the problem :-) Bye, bearophile
Mar 12 2012
On 3/12/12, Ali =C7ehreli <acehreli yahoo.com> wrote:Let's please also see the exact error message. "an error message that seems to indicate that DMD is looking for a global identifier" is not clear to mortals like myself. :)He probably means something like this: struct State { } struct Input { } State[][Tuple!(const(State), const(Input))] transitions; void main() { writeln(transitions.length); } test.d(20): Error: undefined identifier module test.length Note that typeid doesn't work either: writeln(typeid(transitions)); D:\DMD\dmd2\windows\bin\..\..\src\druntime\import\object.di(507): Error: can only initialize const member key inside constructor This seems to be an issue related with const. Without const both calls work= .
Mar 12 2012
On Mon, 12 Mar 2012 19:20:07 +0100, Andrej Mitrovic = <andrej.mitrovich gmail.com> wrote:On 3/12/12, Ali =C3=87ehreli <acehreli yahoo.com> wrote:Let's please also see the exact error message. "an error message that=seems to indicate that DMD is looking for a global identifier" is not==clear to mortals like myself. :)He probably means something like this: struct State { } struct Input { } State[][Tuple!(const(State), const(Input))] transitions; void main() { writeln(transitions.length); } test.d(20): Error: undefined identifier module test.length Note that typeid doesn't work either: writeln(typeid(transitions)); D:\DMD\dmd2\windows\bin\..\..\src\druntime\import\object.di(507): Error: can only initialize const member key inside constructor This seems to be an issue related with const. Without const both calls=work.Weird. You get a different error message from what I get. My reduced code: struct Bar { const int t; } void main( ) { int[Bar] a; int n =3D a.length; } Error message: Assertion failure: 'impl' on line 4407 in file 'mtype.c' abnormal program termination http://d.puremagic.com/issues/show_bug.cgi?id=3D7695
Mar 12 2012
On 2012-03-13 02:27:46 +0000, Simen Kjærås said:Weird.Indeed. Would've thought const AA keys would be reasonable. (In Python they're *required*... :)You get a different error message from what I get. My reduced code:[snip]http://d.puremagic.com/issues/show_bug.cgi?id=7695I guess this issue then covers both (despite the different error messages)? I'll just leave this alone (i.e., not submit any additional tickets), then (and cast away the constness for now; seems to help). -- Magnus Lie Hetland http://hetland.org
Mar 13 2012
On Tue, Mar 13, 2012 at 10:02:02AM +0100, Magnus Lie Hetland wrote:On 2012-03-13 02:27:46 +0000, Simen Kjærås said:[...] I'm of the opinion that AA keys should be *implicitly* immutable. It makes no sense to have mutable AA keys: int[] mykey = [1,2,3,4]; string[int[]] aa; aa[mykey] = "abc"; mykey[0] = 2; // monkey business: mykey has changed but aa // doesn't know about it assert(([1,2,3,4] in aa) !is null); // this will fail But requiring the user to constantly type overly-long type specs like string[immutable int[]] just makes AA's annoying to use, especially if unqualified key types are always illegal. T -- Your inconsistency is the only consistent thing about you! -- KDWeird.Indeed. Would've thought const AA keys would be reasonable. (In Python they're *required*... :)
Mar 13 2012
On 2012-03-13 14:24:37 +0000, H. S. Teoh said:Seconded, whole-heartedly. -- Magnus Lie Hetland http://hetland.orgIndeed. Would've thought const AA keys would be reasonable. (In Python they're *required*... :)[...] I'm of the opinion that AA keys should be *implicitly* immutable.
Mar 13 2012