Re: Nested functions - better example?

new topic     » goto parent     » topic index » view thread      » older message » newer message

According to this a closure is a persistent local variable scope. For Orac what I did was this:

function f() 
  static int x = 2 // persistent var here initialised at runtime 
  int y = x + 1 
  return y 
end function 

The code "compiles" to:

int x = 2 // only accessed by the function 
function f() 
  int y = x + 1 
  return y 
end function 

That gives me persistent private variables. It would, of course, end up being shared across multiple calls to the function. But I never needed anything smarter than that. Or nested functions.

Spock

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu