MathGroup Archive 2007

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

Search the Archive

Re: What is the purpose of the Defer Command?

  • To: mathgroup at
  • Subject: [mg82013] Re: What is the purpose of the Defer Command?
  • From: Szabolcs Horvát <szhorvat at>
  • Date: Tue, 9 Oct 2007 05:42:01 -0400 (EDT)
  • References: <fe4uhp$155$><> <fecak2$fvn$>

Vince Virgilio wrote:
> Your example doesn't go far enough. It shows only an incidental
> syntactic difference.
> Now that I've read the documentation for Defer, I think my comparison
> is quite apt, and that the semantics between Defer and Unevaluated
> align much more than their syntax differs. And yet there is
> significant difference, that is not essentially syntax.

Vince, you're confusing some terms here.  Syntax is the *format* 
(grammar) of a language, not the meaning of language constructs. 
Semantics refers to *meaning*.

Andrzej is right.  With his example, he has shown that Defer and 
Unevaluated have completely different *meanings*, i.e. they affect 
evaluation differently.

> The documentation uses Defer in an example to create cells with
> unevaluated contents. Before, one might try the same with Unevaluated
> (hence the strong relation).

No, Hold[] is the function that serves this purpose, not Unevaluated[].

And for as long as we are concerned only with the structure of 
expressions (and evaluation), Defer and Hold behave in *exactly* the 
same way.   The only difference between them is how they are formatted 
in the Front End.  So Defer is like HoldForm, with the difference that 
copying and pasting its printed form in the Front End will result in 
losing the information that Defer is there.

Defer does not bring anything new to the Mathematica *language* 
(programming).  It is only about formatting.

> But that would give cells with contents
> wrapped in Unevaluated, since Unevaluated is not removed when it's
> Head of "Mathematica input" (Level 0, I suppose). (Substitute
> Unevaluated for Defer in the example to see this.) This is the
> idempotent behavior of Unevaluated. Defer, while it remains as Head of
> Level 0 (your difference), does not show such idempotent behavior (my
> "better-behaved" difference).
> Interesting, and apparently a fix. For why would one ever want
> Unevaluated to linger? (Anyone?) I think Robby Villegas issued a
> related caveat in his notebook on Unevaluated expressions.

Remember how Mathematica evaluation works.  Replacement rules are 
applied until the expression does not change any more.  This requires 
that Unevaluated be processed only when the surrounding expression is 
evaluated (and not before).  Consider f[Unevaluated[1+1]].  Here 
Unevaluated is processed only when 'f' is evaluated.  If Unevaluated 
were removed in the stand-alone expression Unevaluated[1+1], then 
Mathematica would need to go on, and evaluate Plus[1,1] too (to obey the 
rule the replacement rules must be applied for as long as they change 
the expression).

It is simply not possible to have a wrapper function that is always 
removed during evaluation, but its arguments are kept unevaluated.  (I 
mean that it is impossible to do this without changing the basic 
principles upon which the Mathematica language is built.)


  • Prev by Date: Re: What is the purpose of the Defer Command?
  • Next by Date: Re: Change colors in contour plot and including a legend?
  • Previous by thread: Re: What is the purpose of the Defer Command?
  • Next by thread: Re: What is the purpose of the Defer Command?