Re: Sequence as a universal UpValue

• To: mathgroup at smc.vnet.net
• Subject: [mg74632] Re: Sequence as a universal UpValue
• From: "Szabolcs" <szhorvat at gmail.com>
• Date: Thu, 29 Mar 2007 02:29:32 -0500 (EST)
• References: <euan47\$dni\$1@smc.vnet.net>

```On Mar 27, 11:11 am, "Chris Chiasson" <chris at chiasson.name> wrote:
> In his presentation on working with held expressions at
>
> http://library.wolfram.com/conferences/devconf99/villegas/Unevaluated...
>
> Villegas says:
>
> "In fact, Sequence itself could almost be implemented as a universal
> UpValue (maybe Dave Withoff or Roman Maeder remembers if that's not
> quite true)."
>
> So, I am wondering, does the following input disprove that Sequence
> can be implemented as a universal UpValue? How should I think of
> Sequence? Importantly, why doesn't blocking Sequence work like
> blocking the arbitrary symbol?

I'm not sure I understand completely how these things work, but the
behaviour of Block does seem to make sense if you read its help page.
It says:

" When you execute a block, values assigned to x, y, ... are cleared.
When the execution of the block is finished, the original values of
these symbols are restored. "

When you put blahblah in a Block, the definitions associated with it
are cleared, and
its arguments are not spliced into Map. You get the expected result.

But the definitions associated with Sequence are built-in, so they can
not be cleared.

...

Hmm ... Now that I experimented some more, Sequence does seem to be
special in this respect:

In[1]:=
Block[{},Print[f/@{a,b}]]
Block[{Map},Print[f/@{a,b}]]

>From In[1]:=
{f[a],f[b]}

>From In[1]:=
f/@{a,b}

So built-in definitions can be cleared after all. But the Mathematica
book does mention that Sequence is treated in a special way (unlike
other built-ins). Check Section A.4.1 (Mathematica Reference Guide ->
Evaluation -> The Standard Evaluation Sequence).

>
> In[1]:=
> blahblah/:h_[l___,blahblah[blahblahArgs___],r___]=h[l,blahblahArgs,r]
>
> UpValues@blahblah
>
> a[1,blahblah[2,3]]
>
> Block[{Sequence},f/@Sequence[1,2,3]]
>
> Block[{blahblah},f/@blahblah[1,2,3]]
>
> Out[1]=
> h[l,blahblahArgs,r]
>
> Out[2]=
> {HoldPattern[h_[l___,blahblah[blahblahArgs___],r___]]\[RuleDelayed]
>     h[l,blahblahArgs,r]}
>
> Out[3]=
> a[1,2,3]
>
> Map::nonopt: Options expected (instead of 3) beyond position 3 in
> Map[f,1,2,3]. An option must be a rule or a list of rules.
>
> Out[4]=
>
> Map[f,1,2,3]
>
> Out[5]=
> blahblah[f[1],f[2],f[3]]
>