[erlang-questions] Floating guard sequences

Robert Virding rvirding@REDACTED
Thu Feb 19 21:16:44 CET 2009


2009/2/19 fess <fess-erlang@REDACTED>

>
> something like Richards abstract patterns.
>
> also floating guards on the LHS of a match seem like they could make
> code much more concise and readable, and erlang-like [ to me ]
>
>   { X when is_integer(X), [ "x" | Rest ] } = string:to_integer(Str),
>   { Y when is_integer(Y), _ } = string:to_integer(Rest),


Sorry, but I must point out that you can do this in LFE already:

(let* ((#(x ("x" . rest)) (when (is_integer x)) (: string to_integer str))
       (#(y _) (when (is_integer y)) (: string to_integer rest)))
  ... )

Anywhere you can have a pattern you can always follow it with a guard of the
form (when <test>).

Getting back to the question at hand I personally find then more difficult
to read. But that may very well be because I am not used to it.

One good point with this suggestion though is that it moves guards back to
be what they originally were intended, simple tests which were parts the
pattern matching which could not easily be written in the pattern. It might
lessen the confusion of guards not being real expressions.

Robert
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090219/19e7bb8b/attachment.htm>


More information about the erlang-questions mailing list