The uses of Condition (/;)
- To: mathgroup at smc.vnet.net
- Subject: [mg82926] The uses of Condition (/;)
- From: Szabolcs Horvát <szhorvat at gmail.com>
- Date: Sat, 3 Nov 2007 03:31:42 -0500 (EST)
According to the documentation, /; can be used in three different ways,
illustrated below:
A. pattern /; condition = definition
B. pattern := definition /; condition
C. pattern := Module[{}, definition /; condition]
Real examples for testing:
f[x_] /; (Print["cond"]; x > 5) := (Print["def"]; x)
g[x_] := (Print["def"]; x) /; (Print["cond"]; x > 5)
h[x_] := Module[{}, Print["def"]; x /; (Print["cond"]; x > 5)]
Usage C differs from A and B in that 'definition' is always evaluated,
and it is evaluated before 'condition'. But I cannot see *any*
difference in meaning between A and B.
Is B completely redundant? Could someone show an example where an A
type and a B type definition behave differently? Is there any situation
where B can be used, but A cannot? (A is more general: it can be used
with any pattern, while B is restricted to use with SetDelayed and
similar functions.) Is B provided solely as a more readable syntax?
Szabolcs
P.S. Unfortunately usage C is "hidden" in the docs. IMO, since it's
*meaning* (and not only syntax) is different from that of A and B, it
deserves a more prominent place in the docs.
- Follow-Ups:
- Re: The uses of Condition (/;)
- From: "Szabolcs HorvÃt" <szhorvat@gmail.com>
- RE: The uses of Condition (/;). second thoght
- From: "Ingolf Dahl" <ingolf.dahl@telia.com>
- RE: The uses of Condition (/;)
- From: "Ingolf Dahl" <ingolf.dahl@telia.com>
- Re: The uses of Condition (/;)