Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: PrograMing: match without evaluation

  • To:
  • Subject: [mg10262] Re: PrograMing: match without evaluation
  • From: Allan Hayes <>
  • Date: Sat, 3 Jan 1998 05:07:15 -0500
  • References: <684v40$> <68crke$>

Xah wrote:

> How can I define a function f such that when f is matched, certain
> actons are taken and the input is returned unevaluated?


I find the following form useful. Coupled with using Throw and Catch it
allows action to be taken as the function is being evaluated as well as
allowing input checking (possibly using Hold attributes on the left) -
it can be combined with checks on the left which may catch a problem
more quickly .

foo:= With[{result = foointernal} , result./; result =!= $Failed]

Define foointernal to give $Failed, perhaps after issuing a message,
when foo is to be returned unevaluted and to give the intended result 
otherwise. If  $Failed can be an intended result then it will have to
be replace by something else.

An alternative that avoids the last problem is

foo:= Module[{fail, result}, result/; foointernal]

For example

f[x_] := Module[{fail, result, succeed}, result/; If[x>6, fail, result =
x^2; succeed] === succeed]


Allan HayesTraining and Consulting
Leicester, UK
voice: +44 (0)116 271 4198
fax: +44 (0)116 271 8642

  • Prev by Date: 3.0 Typsetting Issues
  • Next by Date: Re: Re: PostScript reader (for MAC)
  • Prev by thread: Re: 3.0 Typsetting Issues
  • Next by thread: Re: Re: PostScript reader (for MAC)