Function Error: cannot be read at compile time
    jmh530 via Digitalmars-d-learn 
    digitalmars-d-learn at puremagic.com
       
    Thu Jun  4 10:04:02 PDT 2015
    
    
  
I'm trying to run the following code (to create an array of 
uniform random variables) on the latest version of rdmd (2.067.1).
import std.random;
auto uniform_array(int len, float a, float b) {
	Random gen;
	float output[len];
	foreach(ref float i; output)
	{
		i = uniform(a, b, gen);
	}
	return output;
}
void main() {
	auto val2 = uniform_array(10, 0.0f, 1.0f);
}
But I get the error
testing_some_stuff.d(5): Error: variable len cannot be read at 
compile time
Failed: ["dmd", "-v", "-o-", "testing_some_stuff.d", "-I."]
I'm not sure why this is an error. The code worked before I put 
it into a function. The function seems to work when I hardcode in 
a length. It's only having some variable length that's a problem. 
I'm not sure why.
    
    
More information about the Digitalmars-d-learn
mailing list