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: p617hfa at sun24.mpifr-bonn.mpg.de (Heino Falcke)
  • Date: Wed, 7 Apr 93 10:16:56 +0200

Dear Mathgroup,

The following question is another example for a user being fooled by
Mathematica shortcuts (and the struggle between pure system
philosopy and the human touch of a program):

I blame neither Michael nor Mma for that, I also wondered a moment -
then I remembered the first lesson I learned in Mma: Never trust your
eyes!

>  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??
> 
>  Michael Trott
> 
>  trott at physik.tu-ilmenau.de
>

It is absolutely O.K. for Mma not print Null in the frist example. The ; is just an abbreviation for CompoundExpression!! You could write instead:

{a,b} /. {x___,a,y___}:>Print[CompoundExpression[z,x]]

In this specific example x is simply not there  (there is more than subtle
difference between `not being' and `being (a) null':-). 
So the expression is correctly evaluated to CompoundExpression[z] as expected.

{,a,b} on the other hand will evaluate to null.

If (as in the second example) you do not use replacements than
z; is of course CompundExpression[z,Null] and evaluates to Null.

Heino

                   ```
                  (o o)
--------------oOO--(_)--OOo------------------------------------------------
 ___      ___   _____   ___   _____  |Heino Falcke
/__/\    /__/| /____/\ /__/| /____/\ |Max-Planck-Institut f. Radioastronomie
|  \ \  /|  || |  o \/ |  || |  o \/ |Auf dem Huegel 69
|  |\ \//|  || |  __/  |  ||f|  __/  |D-W5300 Bonn, Germany
|  ||\_/ |  || |  ||   |  || |  |\ \ |E-mail: HFALCKE at mpifr-bonn.mpg.de
|__|/    |__|/ |__|/   |__|/ |__|/\_||Fax: 49/(0)228/525-229
                                     |Tel.: 49/(0)228/525-285
----------------------------------------------------------------------------
					        
		





  • Prev by Date: another ContourPlot3D question
  • Next by Date: Re: line thickness and ScatterPlot3D
  • Previous by thread: Re: Why printing?
  • Next by thread: RE: M.Trott