       Re: Question on Unevaluated

• To: mathgroup at smc.vnet.net
• Subject: [mg117300] Re: Question on Unevaluated
• From: "Alexey Popkov" <lehin.p at gmail.com>
• Date: Mon, 14 Mar 2011 06:00:55 -0500 (EST)

```Leonid,

Is it possible to imitate the behavior of Unevaluated by setting Attributes in this case:

f[Print, Unevaluated[Print], Print]

?

I am wondering, what attributes are temporarily set when we use Unevaluated and how could I imitate this?

Alexey

----- Original Message -----
From: Leonid Shifrin
To: Alexey ; mathgroup at smc.vnet.net
Sent: Monday, March 14, 2011 1:39 AM
Subject: Re: [mg117264] Question on Unevaluated

Alexey,

You forgot about the CompoundExpression (;). You only attempted to prevent the evaluation of 1+1 inside
(1+1;3), but not the total result for CompoundExpression, which is the value of the last statement
(2+1 in this case). This is what you probably had in mind:

In:= f[Unevaluated[(1 + 1; 2 + 1)]]

Out= f[Unevaluated[1 + 1; 2 + 1]]

What is perhaps less obvious is that you did not prevent the evaluation of 1+1 either. Here is
a simple way to check it:

In:= f[Unevaluated[Print["*"]]; 2 + 1]

During evaluation of In:= *

Out= f

The problem is that Unevaluated is only effective once. To totally prevent something from evaluation,
you have to know the exact number of sub-evaluations (which is generally impossible to know since
it can be data-dependent), and wrap in as many levels of Unevaluated. In this case,  the following will do:

In:= f[Unevaluated[Unevaluated[Print["*"]]]; 2 + 1]

Out= f

But as I said, this is not a robust approach, and in such cases you will be better to use Hold or similar for
a persistent holding wrapper, stripping it off  later when needed. You may want to check out e.g. this thread

(my second post there), where I elaborate on these issues.

HTH.

Regards,
Leonid

On Sun, Mar 13, 2011 at 1:26 PM, Alexey <lehin.p at gmail.com> wrote:

Hello,

I am puzzled a bit by the Documentation for Unevaluated. Under "More

"f[Unevaluated[expr]] effectively works by temporarily setting
attributes so that f holds its argument unevaluated, then evaluating
f[expr].".

After reading this I expect that

f[Unevaluated[1 + 1]; 2 + 1]

will be returned completely unevaluated as it is when I set HoldFirst
attribute to f:

In:= SetAttributes[f, HoldFirst]
f[Unevaluated[1 + 1]; 2 + 1]

Out= f[Unevaluated[1 + 1]; 2 + 1]

But in really we get

In:= f[Unevaluated[1 + 1]; 2 + 1]

Out= f

This leads me to a question: what is implied in documentation? Which
attributes are temporarily set and to which function?

```

• Prev by Date: Re: Joining points of ListPlot
• Next by Date: Re: How to interactively re-scale graphics with mouse?
• Previous by thread: Re: Question on Unevaluated
• Next by thread: Re: Question on Unevaluated