MathGroup Archive 1993

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

Search the Archive

Re: Why printing?

  • To: mathgroup at yoda.physics.unc.edu
  • Subject: Re: Why printing?
  • From: tgayley (Todd Gayley)
  • Date: Mon, 5 Apr 1993 09:44:06 -0600

Michael Trott <Michael.Trott at physik.tu-ilmenau.de> asks:

> Have a look at the following three examples:
> 1.) 
> {a,b}/.{x___,a,y___}:>Print[z;x]
>
> This prints z!!!
>
> 2.)
> {a,b}/.{x___,a,y___}:>Print[z;]
> prints Null (O.K.)
>
> and
>
> 3.)
>
> {a,b}/.{x___,a,y___}:>Print[z;xx]
>
> prints xx (O.K.).
>
>
> The second and third behaviour is O.K. but why is z Printed in the first
> example.
>
> Any ideas??

You are seeing the behavior of Sequence, the magical disappearing head. In
your first example, after pattern matching, a gets a and y gets b. But what
does x become? It becomes Sequence[], which is, in effect, "nothing".

A Sequence beheads itself if it is an argument to _any_ function. In
particular, Sequence[] simply goes away:

In[1]:= f[a,b,Sequence[]]

Out[1]= f[a, b]

Thus, here is what happens in your Print statement:

before substitution:     Print[CompoundExpression[z,x]]
after substitution:      Print[CompoundExpression[z,Sequence[]]]
which becomes:           Print[CompoundExpression[z]].

Compare this to Print[z;] in your second example, which is
Print[CompoundExpression[z,Null]].

The point of this is that when x "disappears" from Print[z;x], you get
Print[z], not Print[z;].


--Todd Gayley






  • Prev by Date: Re: Why printing?
  • Next by Date: RE: M.Trott
  • Previous by thread: Re: Why printing?
  • Next by thread: Re: Why printing?