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 2001

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

Search the Archive

Re: Unevaluated Expression

  • To: mathgroup at
  • Subject: [mg26989] Re: Unevaluated Expression
  • From: Jens-Peer Kuska <kuska at>
  • Date: Tue, 30 Jan 2001 23:22:12 -0500 (EST)
  • Organization: Universitaet Leipzig
  • References: <955v6k$>
  • Sender: owner-wri-mathgroup at

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



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


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 


will replace your argument.

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

And Hold[f[a]] will work


  • 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