Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1993
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

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: John Lee <lee at math.washington.edu>
  • Date: Mon, 5 Apr 93 09:23:48 -0700

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

>  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.


The input form 

  Print[z;] 

is represented internally as 

  Print[ CompoundExpression[z, Null] ] 

When CompoundExpression is evaluated, its value is the value of its last
argument, which is Null.  This explains the result of Example (2).  

The input form x___ on the left-hand side of a function definition means
that the symbol x can represent any number of arguments, including zero.
When x appears on the right-hand side, it is replaced by however many
actual arguments appeared, even if there were zero.  In particular, zero
arguments are NOT replaced by the symbol Null.  Thus your Example (1),
represented internally as

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

evaluates to the following:

  Print[CompoundExpression[z]]]

This explains your surprising output.

Jack Lee
Dept. of Mathematics
University of Washington
Seattle, WA






  • Prev by Date: sequential joining of 3D points
  • Next by Date: Re: Why printing?
  • Previous by thread: Re: sequential joining of 3D points
  • Next by thread: Re: Why printing?