Re: The [] metaoperator

2005-05-14 Thread Juerd
Larry Wall skribis 2005-05-14  8:29 (-0700):
> : 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.

Does this mean that [x] is just an interesting way to create an empty
list? And undef in scalar context?

Very neat for obfuscation: return [%]; and let people wonder why the
heck that [%] is there :)


Juerd
-- 
http://convolution.nl/maak_juerd_blij.html
http://convolution.nl/make_juerd_happy.html 
http://convolution.nl/gajigu_juerd_n.html


Re: The [] metaoperator

2005-05-14 Thread Larry Wall
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


The [] metaoperator

2005-05-14 Thread Autrijus Tang
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?

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?

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()?

Thanks,
/Autrijus/


pgpRdgO9r5PyG.pgp
Description: PGP signature