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

Richard O'Keefe ok@REDACTED
Tue Feb 24 01:14:55 CET 2009


On 23 Feb 2009, at 11:07 pm, Hynek Vychodil wrote:

> Is there way how to define combined patterns like range and odd  
> without define extra new patter for it.

Inside a pattern, the arguments of an abstract pattern may themselves
be patterns.  Roughly speaking,
	... #f(P1, ..., Pn) ...
is like
	... X0 ... when {P1,...,Pn} = '#f'(X0)
This means that
	#range(1, 10, #odd(X))
should work.  But Erlang also has P1 = P2 in patterns,
so you should be able to write
	... #range(1,10,X) = #odd(X) ...

There is such a thing as pushing a notation too far,
and this is getting close.





More information about the erlang-questions mailing list