On Saturday, 31 August 2013 at 21:30:40 UTC, Andrei Alexandrescu wrote:

http://stackoverflow.com/questions/4711309/meaning-of-scope-in-d-for-a-parameter

That use will stay and is useful and uncontested.

Andrei

Sure, but my complaint is that that useful style is cramped by the inability to have scope on *local variables*. I understand that scope on function parameters will stay. If you're saying that scope on local variables for delegates will stay, then disregard all I've written here, I'm happy! :-).

If you look at the code I posted, try removing scope from the 2-D integrate and from the local variable declarations in the main() function, and the program hits the GC, with the scopes, they don't. The problem occurs when I create the local variables to name an anonymous function. I tested this with Adam Ruppe's code which halts when the GC is called.

As I said, I'm not arguing for scope on objects, but for contrivances which allow me to program easily with downward funargs and not hit the GC. D goes further than most languages in this and it would be a shame if this capability is removed with no substitute.

For those who want to test on their systems, here are the trivial unitCircle and unitSphere I omitted.


float unitCircle(float x) {
  float x2 = x * x;
  if (x2 < 1.0) {
    return sqrt(1.0 - x2);
  } else {
    return 0.0;
  }
}

float unitSphere(float x, float y) {
  float sum = x*x + y*y;
  if (sum <= 1.0) {
    return sqrt(1.0 - sum);
  } else {
    return 0.0;
  }
}


-- Brian

Reply via email to