Re: Interrogating closures

2006-11-30 Thread Yuval Kogman
On Thu, Nov 30, 2006 at 09:13:42 -0800, Larry Wall wrote:

> my $x = 42;
> &f := sub {
>   have $.x;
>   say $x;
>   ...
> }
> say &f.x;

hmm... That looks nice.

Maybe even this makes sense:

sub {
have $.x;
method blah { }
}

Conversely, I'd also like to be able to do Closure, which is a
subrole of Code with a constructor. Or rather, an instantiated Code
is a proto of Closure ;-)

-- 
  Yuval Kogman <[EMAIL PROTECTED]>
http://nothingmuch.woobling.org  0xEBD27418



pgp7EJqlaCYtM.pgp
Description: PGP signature


Re: Interrogating closures

2006-11-30 Thread Larry Wall
If I follow what you're saying (and this is by no means a certainty :)
I would tend to look more for a declarative solution than a callback
solution, so I'm imagining that any closure could have a declarator
that explicitly captures an outside lexical and makes it available
as an attribute.  I don't quite want to use "has" though, but it
something possessive.

my $x = 42;
&f := sub {
have $.x;
say $x;
...
}
say &f.x;

Here I'm using the plural possesive to indicate that $x is shared, in
the same sense that "our" is indicating something that's shared, only
in this case it's a shared lexical rather than a shared package variable.

Then you'd just use some variant of ordinary introspection to find
these methods.

But I've probably missed your meta-point entirely...

Larry