Re: Problem with If[] and %

• To: mathgroup at smc.vnet.net
• Subject: [mg5462] Re: [mg5355] Problem with If[] and %
• From: Allan Hayes <hay at haystack>
• Date: Sat, 7 Dec 1996 00:26:41 -0500
• Sender: owner-wri-mathgroup at wolfram.com

```hans.steffani at e-technik.tu-chemnitz.de (Hans Steffani)
[mg5355] Problem with If[] and %
writes

> i^2+v^2
> If[ % >15,15,%]
> Plot3D[ %,{i,-5,5},{v,-5,5}]
>

Hans,

In version 2.2 you can get what you want by replacing
If[ % >15,15,%]
with
If[ Evaluate[% >15],15,Evaluate[%]];
In version 3.0 you can use this or If[ % >15,15,Evaluate[%]]

Here is what lies behind this in version 2.2 (version3.0 is
slightly different - I'll deal with this after).

In evaluating an expression
the first step (the HE step)is, * subject to any attributes of f *,
to evaluate the head and the entries,  f,x,y,z, in turn.
This means that, if f has the attribute HoldAll (as If has in
version 2.2), then the entries x,y,z are held unevaluated, and we
get

Then the *rules* for evaluating (1) are used.

In the evaluation of your original code the HE step in the
evaluation of If[ % >15,15,%] simply gives (because If has the
attribute Hold all an the value of If is If)

Then the rules for evaluating (2) are used.
With the change suggested, the HE step in the evaluation of
If[ Evaluate[% >15],15,Evaluate[%]] gives

Then the rules for evaluating (3) are used:
In version 3.0 If has the attribute HoldRest (so in the HE step the
first entry is evaluated). This is the reason that you can use

Incidentally, you get the same picture with

i^2+v^2
Plot3D[ %,{i,-5,5},{v,-5,5}, PlotRange -> {0,5}]

and you can modify the clipped part with the option ClipFill.

Allan Hayes
hay at haystack.demon.co.uk
http://www.haystack.demon.co.uk

```

• Prev by Date: If[] and % problem
• Next by Date: symbol manipulation
• Previous by thread: Problem with If[] and %
• Next by thread: Re: Problem with If[] and %