MathGroup Archive 2000

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

Search the Archive

Re: Non-standard evaluation

  • To: mathgroup at smc.vnet.net
  • Subject: [mg22081] Re: [mg22078] Non-standard evaluation
  • From: Andrzej Kozlowski <andrzej at platon.c.u-tokyo.ac.jp>
  • Date: Sun, 13 Feb 2000 01:13:58 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

on 00.2.12 6:04 PM, Stig Sandnes at stigsa at math.uio.no wrote:

> I got the following output using my student-version
> of Mathematica:
> 
> ----
> In[1]:=SetAttributes[j,HoldAll]
> 
> In[2]:=j[1,Unevaluated[2],3,4,5]
> Out[2]=j[1,Unevaluated[2],3,4,5]
> 
> In[3]:=j[1,Unevaluated[2],3,Sequence[4,5]]
> Out[3]=j[1,2,3,4,5]
> 
> In[4]:=$Version
> Out[4]="Microsoft Windows 3.0 (April 25, 1997)"
> ----
> 
> Can anybody reproduce this with Mathematica version 4?
> I don't understand why the Unevaluated-wrapper isn't
> stripped in the first case too. Maybe not an important
> problem, but it looks like a bug too me...

I don't think there is anything wrong here (and by the way, this behaviour
is the same in Mathematica 4.0). The HoldAll attribute has nothing to do with what
happens, and you will get the same behaviour without it. Unevaluated is
normally not stripped by "inert functions" which "do not do anything". In
fact it is  the behaviour caused by the presence of Sequence that is a
little bit strange, but than Sequence is a magic function!

An "inert" function need not be a function without any definiton, as in your
case above. To see what I mean let's consider an extremely common function,
which also "does nothing".

In[1]:=
List[2, Unevaluated[3], 4, 5]

Out[1]=
{2, Unevaluated[3], 4, 5}

As you see Unevaluated does not get stripped.  But now if you insert a
Sequence inside:

In[2]:=
List[2, Unevaluated[3], Sequence[4, 5]]
Out[2]=
{2, 3, 4, 5}

It was the presence of Sequence and its "flattening out"  that caused to the
stripping of Unevaluated. You can see that also in your example. The HoldAll
attribute has nothing at all to do with this pehnomenon, but we shall give f
the SequenceHold attribute (or HoldAllComplete if you prefer):

In[6]:=
ClearAll[f]

In[7]:=
SetAttributes[f,  SequenceHold]

In[8]:=
f[2, Unevaluated[3], Sequence[4, 5]]

Out[8]=
f[2, Unevaluated[3], Sequence[4, 5]]

Unevaluated is not stripped. But now clear the SequenceHold attribute:

In[9]:=
ClearAttributes[f, SequenceHold]

In[9]:=
f[2, Unevaluated[3], Sequence[4, 5]]

Out[9]=
f[2, 3, 4, 5]





  • Prev by Date: Re: Sorting
  • Next by Date: Re: Sorting
  • Previous by thread: Non-standard evaluation
  • Next by thread: is it possible to solve this?