[erlang-questions] abstract patterns vs macros was:( Floating guard sequences)

fess fess-erlang@REDACTED
Thu Feb 19 19:53:54 CET 2009


On Feb 17, 2009, at 4:51 PM, Richard O'Keefe wrote:

> Abstract patterns, however, do increase expressiveness,
> can improve readability, and do solve the "no way to name
> a repeated condition" problem, *without* introducing
> potentially unbounded or side-effective computation into
> matching.  And they're hygienic, not like macros.
>
> 	#natural(X) when is_integer(X), X >= 0 -> X.
>
> 	f(#natural(X), ...) when ... -> ...
> 	f(..., #natural(Y)) when ... -> ...
>
> Abstract patterns really are a good idea.

I do this sort of thing with macros,

-define(is_natural(X), is_integer(X), X >= 0 ).

f(X, ...) when ?is_natural(X) -> ...

I'm sure I can learn something by asking,  why not just do this with  
macros?


--fess






More information about the erlang-questions mailing list