View mode: basic / threaded / horizontal-split · Log in · Help
March 12, 2012
Why doesn't this have a length?
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
March 12, 2012
Re: Why doesn't this have a length?
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
March 12, 2012
Re: Why doesn't this have a length?
On 03/12/2012 08:59 AM, bearophile wrote:
> 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

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. :)

Ali
March 12, 2012
Re: Why doesn't this have a length?
On 3/12/12, Ali Çehreli <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.
March 13, 2012
Re: Why doesn't this have a length?
On Mon, 12 Mar 2012 19:20:07 +0100, Andrej Mitrovic  
<andrej.mitrovich@gmail.com> wrote:

> On 3/12/12, Ali Çehreli <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 = 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=7695
March 13, 2012
Re: Why doesn't this have a length?
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=7695

I 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
March 13, 2012
Re: Why doesn't this have a length?
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:
> 
> >Weird.
> 
> Indeed. 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. 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! -- KD
March 13, 2012
Re: Why doesn't this have a length?
On 2012-03-13 14:24:37 +0000, H. S. Teoh said:

>> Indeed. 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.

Seconded, whole-heartedly.

-- 
Magnus Lie Hetland
http://hetland.org
Top | Discussion index | About this forum | D home