Re: Question about .sort and .reduce

2008-07-12 Thread Larry Wall
On Fri, Jul 11, 2008 at 03:27:26PM +0200, TSa wrote:
 HaloO,

 Patrick R. Michaud wrote:
 S29 doesn't show a 'sort' method defined on block/closure
 invocants... should there be?  

 I doubt that. And to my eyes it looks funny. Only real block
 methods should be useful and since the class is mostly known
 at parse time unapplicable methods should be a compile error.

my f = { $^a = $^b }.assuming($^a = 3);

say f(3); # prints 0

 Would that be valid? I mean the usuage of automatic variables
 in the assuming method?

No, that could not work, because $^a = 3 would be in an rvalue context
and refer to the block around the entire statement as a different
parameter.  Setting a named parameter with .assuming must use named
argument notation:

my f = { $^a = $^b }.assuming(:a(3));

Also, it may well be that f(3) will say Order::Same rather than 0.  :)

Larry


Re: Question about .sort and .reduce

2008-07-12 Thread Larry Wall
On Fri, Jul 11, 2008 at 09:01:09AM -0500, Patrick R. Michaud wrote:
: I'm not entirely certain if any of the following 
: examples with adverbial blocks would also work.  I'm guessing
: they do, but could use confirmation.
: 
: sort @a, :{ $^a = $^b };
: sort @a :{ $^a = $^b };
: sort :{ $^a = $^b }, @a;
: @a.sort: :{ $^a = $^b };

I think they all work, but the second one is fragile and will break
if you replace @a with an expression containing an operator that the
adverb would attach itself to instead of to the sort, since adverbs
in infix position always pick the most recent operator (that isn't
hidden inside brackets or parens).

Larry


Re: Question about .sort and .reduce

2008-07-11 Thread TSa

HaloO,

Patrick R. Michaud wrote:

S29 doesn't show a 'sort' method defined on block/closure
invocants... should there be?  


I doubt that. And to my eyes it looks funny. Only real block
methods should be useful and since the class is mostly known
at parse time unapplicable methods should be a compile error.

   my f = { $^a = $^b }.assuming($^a = 3);

   say f(3); # prints 0

Would that be valid? I mean the usuage of automatic variables
in the assuming method?



Note that we already have:

my @s = sort { $^a = $^b }, @a;
my @s = @a.sort { $^a = $^b };


Is that the adverbial block syntax? If not how
would it look?

  my @s = sort @a :{ $^a = $^b };

Or with a comma after @a?


Regards, TSa.
--

The unavoidable price of reliability is simplicity -- C.A.R. Hoare
Simplicity does not precede complexity, but follows it. -- A.J. Perlis
1 + 2 + 3 + 4 + ... = -1/12  -- Srinivasa Ramanujan


Re: Question about .sort and .reduce

2008-07-11 Thread Patrick R. Michaud
On Fri, Jul 11, 2008 at 03:27:26PM +0200, TSa wrote:
 Note that we already have:
 
 my @s = sort { $^a = $^b }, @a;
 my @s = @a.sort { $^a = $^b };
 
 Is that the adverbial block syntax? If not how
 would it look?

The adverbial block syntax would be:

@a.sort:{ $^a = $^b };
sort(@a) :{ $^a = $^b };

I'm not entirely certain if any of the following 
examples with adverbial blocks would also work.  I'm guessing
they do, but could use confirmation.

sort @a, :{ $^a = $^b };
sort @a :{ $^a = $^b };
sort :{ $^a = $^b }, @a;
@a.sort: :{ $^a = $^b };

Pm