Re: Unevaluated Expression

• To: mathgroup at smc.vnet.net
• Subject: [mg26989] Re: Unevaluated Expression
• From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
• Date: Tue, 30 Jan 2001 23:22:12 -0500 (EST)
• Organization: Universitaet Leipzig
• References: <955v6k\$1i@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Hermann Meier 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.

If you don't want, that f[] gets evaluated why do you define
rules for the evaluation ???

The definition:

SetAttributes[f, HoldAll]

f[x_Symbol] := (Print["huhu"]; x^2)
f[x_?NumericQ] := x^2

and

f[a]

will Print[] "huhu" because a is left unevaluated (due to the
attribute) and the a_Symbol pattern matches.

While

g[x_Symbol] := (Print["huhu1"]; x^2)
g[x_?NumericQ] := x^2

and g[a] will a evaluate to 10 and use the second rule and no "huhu1"
is printed.

>
> 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 ?

The argument isn't firing the right hand side of the rule

f[x_]:=

you don't want that f[] is evaluated instead of an unevaluated argument.

And Hold[f[a]] will work

Regards
Jens

```

• Prev by Date: Re: Queries: notebook, matrices
• Next by Date: Re: How can I creat a user coordinate system for my routine?
• Previous by thread: Unevaluated Expression
• Next by thread: RE: Unevaluated Expression