------------------------------------------------
On Thu, 19 Dec 2002 17:44:22 +0100, "Jenda Krynicky" <[EMAIL PROTECTED]> wrote:

> From: [EMAIL PROTECTED]
> > ------------------------------------------------
> > On Thu, 19 Dec 2002 11:04:27 -0500, [EMAIL PROTECTED]
> > wrote:
> > > But is it not wrong to create an array in a function and send a
> > > reference to the array back into the main function?
> > > 
> > > Because the scope of the array is limited to the function and
> > > calling a reference that is not available(the variables local in
> > > scope to the function are collapsed) must be illegal!!
> > > 
> > > Regards,
> > > Satya
> > 
> > You have just learned what a closure is :-).  At least that is my
> > understanding of one.  
> 
> No this is not a closure.
> 
> This is:
>       sub createClosure {
>               my $x = shift;
>               return sub { print $x++,"\n" }
>       }
> 
>       $closure = createClosure( 5 );
>       $closure->();
>       $closure->();
> 
> Closure is a function that references a variable lexical to the scope 
> it was created in even though the scope is long gone.
> 
> Jenda


Obviously I never did quite get that.  But your explanation makes sense to me. So it 
is similar to what he had only rather than it being a reference directly (aka as a 
scalar) to the other value, it is a reference to a subroutine that then accesses the 
value?

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to