       Re: Unevaluated Expression

• To: mathgroup at smc.vnet.net
• Subject: [mg26999] Re: [mg26962] Unevaluated Expression
• From: Andrzej Kozlowski <andrzej at tuins.ac.jp>
• Date: Tue, 30 Jan 2001 23:22:19 -0500 (EST)
• Sender: owner-wri-mathgroup at wolfram.com

```I am afraid that you do not make it clear enough (at least for me) what
really you would like f to return. For example, why is the following simple
method not satisfactory?

In:=
f[x_] := x^2
In:=
a = 10:
In:=
f[HoldForm[a]]
Out=
2
a
In:=
ReleaseHold[%]
Out=
100

Alternatively perhaps you prefer the arguments of f not evaluate at all
(without needing HoldForm in the input):

In:=
Clear[f]
In:=
SetAttributes[f, HoldAll]
In:=
f[x_] := HoldForm[x]^2
In:=
f[a]
Out=
2
a
In:=
ReleaseHold[%]
Out=
100

And by the way, I can't understand the point of the codes you give at the
end of your posting. In particular, Composition[Hold] evaluates simply to
Hold, and f plays no role at all in the code, it might equally well be
replaced by any atomic expression you like, for example 0:

In:=
First[Level[Composition[Hold][f[#]], {-1}]] & /@ {a, 10}

Out=
{10, 10}

In:=
First[Level[Composition[Hold][0[#]], {-1}]] & /@ {a, 10}

Out=
{10, 10}

In:=
First[Level[Hold[0[#]], {-1}]] & /@ {a, 10}

Out=
{10, 10}

--
Andrzej Kozlowski
Toyama International University
JAPAN

http://platon.c.u-tokyo.ac.jp/andrzej/
http://sigma.tuins.ac.jp/

on 01.1.30 5:38 PM, Hermann Meier at hmeier at webshuttle.ch wrote:

> Dear Mathematica users,
>
> a = 10;
> Unprotect[ToString]; SetAttributes[ToString, HoldAll]
> ToString[a]//FullForm
> gives (as desired) "a", not 10
>
>
> Then I wanted to prevent the argument in f[x_] := x^2  from
> getting evaluated.
>
> Attributes[f] = {HoldAll}
> f[x_] := x^2
> f[Unevaluated[a]]
> gives 100.
>
> The longwinded code
> ToExpression[ToString[f[a]], InputForm, Hold] /. Hold[f[nr_]] -> nr
> or
> First[Level[Composition[Hold][f[#]],{-1}]]& /@ {a,10}
>
> at least manages to give 10 instead of 100.
>
> Is there really no way to prevent the argument in f[x] from firing ?
> (I use Mathematica 4.1 for Windows).
>
>
> With best regards
> Hermann Meier
>
>
>
>
>
>
>
>
>
>

```

• Prev by Date: RE: RE: 1. Input of screen coordinates; 2. Fast graphics
• Next by Date: Re: Queries: notebook, matrices
• Previous by thread: RE: Unevaluated Expression
• Next by thread: Queries: notebook, matrices