[erlang-questions] Floating guard sequences

fess fess-erlang@REDACTED
Fri Feb 20 02:31:00 CET 2009


On Feb 19, 2009, at 3:53 PM, Richard O'Keefe wrote:

> and then to write a plain
>
> 	{ok,X,[$x|Rest]} = better_to_integer(Str),
> 	{ok,Y,_        } = better_to_integer(Rest)
>
> Testing whether X or Y is an integer ASKS THE WRONG QUESTION.
> A better question is "is this not the atom 'error'"?
> But the best question is the one we really want: "is this
> conversion ok?"  And fixing the interface lets us ask very
> simply what we really mean.


This makes a lot of sense.   and I think I should have added  
better_to_integer instead of using case clauses. Even with floating  
guards I think that the simpler match off of a better_to_integer is  
more clear.  [ clarity always being subjective.. :) ]

However this case made me realize that pattern matching in the '='   
had less power than in a case clause or a function clause where the  
guards were possible.  So that more balanced approach is what seemed  
interesting to me about Michael's proposal.

For the function/case clauses where I've used macros for common  
pattern matches where i'd like guards but can't have them at the same  
time.  I see how that is addressed better by the abstract patterns,   
so I'd vote for something like that too.


--fess



More information about the erlang-questions mailing list