Can pattern variables be globally bound?
Roger Price
rprice@REDACTED
Wed Mar 29 00:22:18 CEST 2006
On Tue, 28 Mar 2006, Thomas Johnsson wrote:
> This is a messy corner in Erlang... Although same variables in patterns
> in function heads and case expressions means equality, 'equality-ness'
> does not propagate into fun()'s and list comprehensions, instead they
> denote new variables with the same name:
>
> f(X,Y) -> %3
> F = fun(X) -> {X,X} end, %4
> F(Y). %5
> ...
This is disconcerting. I had assumed that a case expression such as
case Expr
of (P1) -> E1
; (P2) -> E2
end
could be defined as
fun (P1) -> E1
; (P2) -> E2
end (Expr)
but now it appears this is not true, since the fun introduces new
variables in the patterns P1 and P2, which the case expression does not.
Roger
More information about the erlang-questions
mailing list