[erlang-questions] Floating guard sequences

Michael Radford <>
Fri Feb 20 01:22:51 CET 2009


Zvi writes:
>  much more readable, if we can marry patterns with guards:
> 
>    { X = int(), [ "x" | Rest ] } = string:to_integer(Str),
>    { Y = int(), _ } = string:to_integer(Rest),
> 
> where int() is patten matching any integer value.

Yes, it would be wonderful if the pattern syntax treated all the
primitive types equally.  It's a bit weird that tuples and lists can be
recognized by patterns, but everything else needs a guard.

(For the record, my proposal was not meant to say "here's my ideal
syntax," but rather to say "here's a compatible and relatively minimal
change that would allow patterns to contain what we currently need
separate guards to achieve.")

I think you'd need some other character to distinguish these primitive
type patterns from normal function calls, maybe something like:

	{ X = :integer(), _ } = ...
	{ Y = :integer(0, 255), _ } = ...
	{ Z = :function(2), _ } = ...

(It does seem nice to make them as close to the is_XXX guards and edoc
spec notation as possible.)

Mike



More information about the erlang-questions mailing list