Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2000
*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 2000

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

Search the Archive

A simple programming question.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg23174] A simple programming question.
  • From: Jack Goldberg <jackgold at math.lsa.umich.edu>
  • Date: Thu, 20 Apr 2000 23:48:45 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Hi group;

In a post by Russell Towle [mg23117] appears a short 
program written by David Park from an idea of Carl Woll.
Here it is:

OrderedUnion2[li_] :=
	Block[ {i},
		i[n_] := (i[n] = Null; n);
		i /@ li
	]

I understand about 98% of what's going on, but one item
keeps eluding me.  What is the role of the parentheses in 
the first line of the Block?  Without () the program fails
and as is, the program inserts Null after the second time 
it sees the same number in li.  That is, 

	{1,1,2,3,4,3} => {1, Null, 2, 3, 4, Null}

I understand the point of  i[n_] := i[n]=Null and I think 
I understand the role of  the  "n" after the ";"  - but I 
don't quite get the whole picture.  Presumably, the point 
is not to have Null substituted for all entries in li but 
only the duplicates... But what role does () play in all this?

A second related question.  In order to understand the 
"inner workings" I used Trace to no avail; I looked up 
CompoundExpression to no avail; I tried Print[] at 
various spots, also to no avail.  Can anyone recommend
a scheme that could have helped me understand what was 
going on?  

Someone care to guide me here?  Thanks,

Jack




  • Prev by Date: Re: Printing Mathematica in MSWord
  • Next by Date: Re: Piecewise functions
  • Previous by thread: Yet another Display[...,...,"PDF"]-Problem
  • Next by thread: Re: A simple programming question.