Re: problem writing debugging utility function

*To*: mathgroup at smc.vnet.net*Subject*: [mg100319] Re: problem writing debugging utility function*From*: Szabolcs <szhorvat at gmail.com>*Date*: Mon, 1 Jun 2009 07:05:59 -0400 (EDT)*References*: <gvq09k$mqv$1@smc.vnet.net> <gvtmku$gk9$1@smc.vnet.net>

On May 31, 1:37 pm, "dabro... at indiana.edu" <dabro... at indiana.edu> wrote: > > The Unevaluated[] function had slipped off my radar, probably because > I never fully grokked the distinction between it and Hold[]. In fact > I'm still a bit confused about it. At first I thought it might like > the evaluation inhibitor ` in Lisp, but some examples disabused me of > that. > > In[2]:= f@Unevaluated[5 + 6 + 7 + 8] > > Out[2]= f[Unevaluated[5 + 6 + 7 + 8]] > > In[11]:= ToString@Unevaluated[5 + 6 + 7 + 8] > > Out[11]= "5 + 6 + 7 + 8" > > I might have expected Out[11]= "Unevaluated[5 + 6 + 7 + 8]" > > In[13]:= sqr[x_] := x^2 > > In[14]:= sqr@Unevaluated[5 + 6 + 7 + 8] > > Out[14]= 676 > > I might have expected Out[14]= sqr[5 + 6 + 7 + 8] since sqr does not > know what to do with the pattern _+_+_+_ or _+_ for that matter. > Could anyone elucidate this for me? Unevaluated[] is treated in a special way during evaluation. There's a good explanation of what it does in the docs, under 'More information': "f[Unevaluated[expr]] effectively works by temporarily setting attributes so that f holds its argument unevaluated, then evaluating f [expr]." http://reference.wolfram.com/mathematica/ref/Unevaluated.html There's also a very detailed explanation somewhere in the docs of how exactly expressions are evaluated by the kernel. You can look that up if you're interested. It's no wonder if you're confused about Unevaluated/Hold/etc. and evaluation order. They can be confusing. People are usually pointed to the paper titled 'Working with Unevaluated Expressions' by Robby Villegas. There's a link to it here: http://library.wolfram.com/conferences/devconf99/