develooper Front page | perl.perl6.language | Postings from April 2005

Re: Closure/block/sub multiplier /// Win32 module for Perl6

Thread Previous | Thread Next
April 20, 2005 10:09
Re: Closure/block/sub multiplier /// Win32 module for Perl6
Message ID:
Matt skribis 2005-04-20 13:00 (-0400):
> 1. I know there is the xx operator for repeating strings.  I also know you  
> can use XX for repeating either closures, blocks, or subs; though I'm not  
> sure which.  Assuming you could use XX on a sub, how would you gather the  
> results into an array?
> @names = &get_next(...) XX 5;

I'm not sure the XX thing will happen, but if it does, it'd be most
useful if it wouldn't treat a sub call differently.

In other words,

    @random = { rand } XX 5;

would return 5 different random values, while

    @random = { rand }() XX 5;

would do exactly the same as

    @random = rand xx 5;

And your

    @names = &get_next(...) XX 5;  # Why the &, by the way?

I think should be

    @names = { get_next(...) } XX 5;

or, if get_next doesn't take arguments,

    @names = &get_next XX 5;

Note that if the ... should change each of the 5 times, then this should
be done using map:

    1..5 ==> map { get_next($_) } ==> @names;

or of course

    @names = map { get_next($_) }, 1..5;

The XX was proposed mainly because the 1..5 part of map often does not
make sense as a range, and in those cases you just abuse it for


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About