On Tue, 30 Nov 2004, David Christensen wrote:

Incidentally, just like mathematically (albeit slightly loosely) an element of a set can be thought of as a function from any singleton, would it be possible for Perl 6 to provide a fast (under the syntactical point of view) way to promote a term to a function returning it?

What's wrong with the perl 5:

sub mysub($x) {
        return sub { $x };  # the sub{$x} is the construct
}


or the perl6

$xsub = { $x };

I am a little confused if the following is valid perl6:

our &xsub = { $x };

I believe that would work and install this function in the package global symbol table because &xsub is the reference to the function xsub.

If you wanted to get a function for each element in an array @a, I suppose you can say:

sub makefunc($x){{$x}}
@funcarray = @a>>.makefunc;

And that can also be shortened to:

@funcarray = @a>>{my $x=$^x;{$x}};

--abhijit



Reply via email to