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

Re: The [] metaoperator

Thread Previous | Thread Next
From:
Larry Wall
Date:
May 14, 2005 08:29
Subject:
Re: The [] metaoperator
Message ID:
20050514152914.GA11604@wall.org
On Sat, May 14, 2005 at 10:53:38PM +0800, Autrijus Tang wrote:
: On Sat, May 14, 2005 at 10:56:29PM +1000, Damian Conway wrote:
: >     8. To verify the monotonicity of a sequence:
: > 
: >            $is_monotonic = [<] @numbers;
: 
: Hey.  Does this mean that the [] metaoperator folds with the
: associativity of the operator inside it?

Yes.  It's as if there is a long cat, only without the cat.

: That is, if the operator inside is right-associative, it functions as
: foldr; if the operator is left-associative, it functions as a foldl; and
: if the operator is chain-associative like <, it assumes the special,
: short-circuiting chained-folding semantic?
: 
:     [>]  1, 2, 3;    # 1 > 2 > 3	# 3 is not evaluated
:     [**] 1, 2, 3;    # 1 ** (2 ** 3)
:     [+]  1, 2, 3;    # (1 + 2) + 3
: 
: If so, should I send patches to S03, or is it already in the works?

Feel free, unless someone else volunteers.

: Finally, what does this mean?
: 
:     say [x];
: 
: Is it a repeating metaoperator on an empty list, or a single-element
: array reference that contains the return value of calling &x()?

Always the first.  [x] doesn't have to do lookahead.

Larry

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About