Wither Self

Richard A. O'Keefe <>
Wed Sep 10 04:05:53 CEST 2003


Raimo Niskanen <> wrote:
	If the compiler would check for unbound variables in the right
	side of match expression *after* the pattern match, how would the
	following be treated?
	
	     {Even, Odd, Strange} =
	         {fun(0) -> true;  (N) -> Odd( N-1) end,
	          fun(0) -> false; (N) -> Even(N-1) end,
		 Strange},
	
I most certainly did NOT say "check for unbound variables in the right
side of match expression"!  What I wrote was quite explicit:

	> If you have
	>     <pattern> = ... <fun> ...
                                               vvvvvvv
	> then the check for unbound variables in <fun> should ask whether
                                               ^^^^^^^
	> any variable will still be unbound *after* the pattern is matched
	> instead of whether any variable is unbound *before* the pattern match.

In your example,

             {Even, Odd, Strange} =
                 {fun(0) -> true;  (N) -> Odd( N-1) end,
                                          ^______________ *IS* in a <fun>
                  fun(0) -> false; (N) -> Even(N-1) end,
                                          ^______________ *IS* in a <fun>
                 Strange},
                 ^_______________________________________ is *NOT* in a <fun>

The change applies only to <funs>, and I should have said that it should
apply only to those <funs> which are only enclosed by [..] {..} constructors;
a <fun> which is an argument of a function call should be checked like the
rest of the expression.

In the example
	
	     {Even, Odd, Strange} =
	         {fun(0) -> true;  (N) -> Odd( N-1) end,
                                          ^______________ *IS* in a <fun>
	          fun(0) -> false; (N) -> Even(N-1) end,
                                          ^______________ *IS* in a <fun>
		 {very,Strange}},
                       ^_________________________________ is *NOT* in a <fun>	

the alleged problem is again fictitious.

	or do you mean that it is just fun()s unbound variables that
	should be checked after the pattern match binding?
	
Yes.  That's why I _said_ so.




More information about the erlang-questions mailing list