in reply to Functional Composition
'|' is left associative, and the left argument is evaluated first
Left-associative means that
is equivalent toa | b | c
and not( a | b ) | c
a | ( b | c )
It says nothing about the order in which a, b and c are evaluated in relation to each other. In fact, the operand evaluation order is undefined for most Perl operators including the "|" operator.
Perl is free to evaluate
as follows:a | b | c
push @stack, c; push @stack, b; push @stack, a; push @stack, pop(@stack) | pop(@stack); push @stack, pop(@stack) | pop(@stack); pop @stack;
The left pipe is evaluated before the right pipe, so the operator is left-associative, but note how c is evaluated before b, which is evaluated before a.
Your code is relying on undefined functionality. It's not guaranteed to work. You'd have to switch to || if you wanted predictable results. || is guaranteed to evaluate its LHS argument before its RHS argument due to its short-circuiting nature.
That's the official line, anyway. In reality, |'s LHS arg is always evaluated before its RHS, and I don't see that ever changing.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Functional Composition
by billh (Pilgrim) on Dec 17, 2009 at 21:19 UTC | |
by ikegami (Patriarch) on Dec 17, 2009 at 21:22 UTC | |
by billh (Pilgrim) on Dec 17, 2009 at 22:02 UTC | |
by ikegami (Patriarch) on Dec 18, 2009 at 01:09 UTC |