Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2007
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2007

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

Search the Archive

RE: & without #

  • To: mathgroup at smc.vnet.net
  • Subject: [mg73111] RE: [mg73042] & without #
  • From: "Virgilio, Vincent - SSD" <Vincent.Virgilio at itt.com>
  • Date: Sat, 3 Feb 2007 04:52:22 -0500 (EST)

& is short for Function, which has attribute HoldAll.  So  Random
reevaluates on each iteration of Array in your first example.  Hence the
unique samples. And Function "eats" the iterator value.

Random evaluates once in your second example.  Hence the value 3 for
each Array iteration.  3 is not a Function, so does not eat the iterator
value.

Vince Virgilio

-----Original Message-----
From: Kristen W Carlson [mailto:carlsonkw at gmail.com] 
Sent: Tuesday, January 30, 2007 11:41 PM
To: mathgroup at smc.vnet.net
Subject: [mg73111] [mg73042] & without #

Hi,

To: mathgroup at smc.vnet.net

L=Array[Random[Integer,10]&,20]

{4,5,9,6,8,5,4,0,9,4,5,2,10,6,3,7,4,2,2,8}

Here is what happens without the &:

L=Array[Random[Integer,10],20]

{3[1],3[2],3[3],3[4],3[5],3[6],3[7],3[8],3[9],3[10],3[11],3[12],3[13],3[
 14],3[15],3[16],3[17],3[18],3[19],3[20]}

Can someone who understands this please explain as completely as you
can, including how & and # work together, given the behavior of & alone.
And is this documented anywhere?

This might help and I also post it to help illuminate for those who
haven't seen this & usage; it is from Andrzej a while ago (Andrzej I
hope you don't mind):

In general it means a constant function. For example 3& will return 3
with any argument. But the are at least two "special" functions, which
will work like "variable constants" when used in this way. One of them
is Random[]& (and various variants of it). Another is Unique [symbol]&,
which on every evaluation will produce a unique name based on "symbol".

Kris


************************************
This e-mail and any files transmitted with it are proprietary and intended solely
for the use of the individual or entity to whom they are addressed. If you have
received this e-mail in error please notify the sender. Please note that any views
or opinions presented in this e-mail are solely those of the author and do not
necessarily represent those of ITT, Inc. The recipient should check
this e-mail and any attachments for the presence of viruses. ITT accepts
no liability for any damage caused by any virus transmitted by this e-mail.
************************************


  • Prev by Date: NIntegrate - problems with HoldAll property(?)
  • Next by Date: Re: Solve, when I already know 1 solution
  • Previous by thread: Re: & without #
  • Next by thread: Re: fundamental Integrate question