turtles features (Was: Flag proposal)

2011-06-13 Thread Timon Gehr
Andrei Alexandrescu wrote:
 module my_module;

 void fun()
 {
  import std.random;
  return uniform(0, 100);
 }

 int gun()
 {
  import std.stdio;
  writeln(fun());
 }

 This module won't compile in today's D, but not for a matter of
 principles; it's just a random limitation of the language. (It does work
 if you import from within a class or struct.) You can insert most
 declarations in a scope, so the ones you can't insert are just awkward
 exceptions, unless there's a good reason to actively disable them. Any
 code should work if you just wrap another scope around it.


//void main(){
immutable a = b;
immutable b = 1;

int foo(int n){
if(n==1) return 1;
return 1+bar(n);
}

int bar(int n){
if(n1) return foo(3*n+1);
return foo(n/2);
}
//}

Will this be fixed too?

Timon


Re: turtles features (Was: Flag proposal)

2011-06-13 Thread bearophile
Timon Gehr:

 Will this be fixed too?

Mutually recursive inner functions are not so common, and there is a 
workaround, making one of them a delegate defined before.

But what about this?

auto foo()()
out(result) {
} body {
return 0;
}
void main() {
foo();
}


test.d(1): Error: function test.foo!().foo post conditions are not supported if 
the return type is inferred
test.d(7): Error: template instance test.foo!() error instantiating
test.d(7): Error: forward reference to inferred return type of function call foo

This is a common problem for my code, is it possible to fix (support) this? (In 
functional-style code auto return values are sometimes almost necessary).

Bye,
bearophile