On Sun, May 18, 2003 at 06:08:43PM +0900, MikkelFJ wrote:
> > > A quick question.  How can one discern when an object goes out of scope?
> > > I'd like to do something like this:
> >
> > Objects don't have scope.  Variables do.  (a subtle distinction)
> 
> > Use a block to manage resources.  Like this ...
> 
> Still, it would actually be nice to have a feature in Ruby that would
> trigger a finalizer when the variable goes out of scope. There are problems
> becuase there could be more references at the time of finalization, but this
> could also  be the case with cleanup using structs. I.e. closing a file
> doesn't guarantee there are no more references to the file.

The 
    SomeClass.get_resource do |r|

    end

idiom addresses this perfectly, IMHO.
 
> See the auto attribute of the D programming language:
> 
> http://www.digitalmars.com/d/attribute.html#auto

It seems D is a statically typed language... (but I've
just read a little bit following your link). Moreover,
http://www.digitalmars.com/d/function.html#closures seems to indicate
that it doesn't have real closures. These make it difficult to know when
a variable "goes out of scope", as it's no longer a syntactic issue (ie.
what's the "scope" then?).

<quote>
 A delegate can be set to a non-static nested function:

	int delegate() dg;

	void test()
	{   int a = 7;
	    int foo() { return a + 3; }

	    dg = foo;
	    int i = dg();	// i is set to 10
	}
	

The stack variables, however, are not valid once the function declaring
them has exited, in the same manner that pointers to stack variables are
not valid upon exit from a function:

	int* bar()
	{   int b;
	    test();
	    int i = dg();	// error, test.a no longer exists
	    return &b;		// error, bar.b not valid after bar() exits
	}
</quote>	

-- 
 _           _                             
| |__   __ _| |_ ___ _ __ ___   __ _ _ __  
| '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ 
| |_) | (_| | |_\__ \ | | | | | (_| | | | |
|_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_|
	Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

* Linux Viruscan.....
  Windows 95 found.  Remove it? (Y/y)
	-- Unknown source