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: [mg73090] Re: & without #
  • From: dh <dh at metrohm.ch>
  • Date: Thu, 1 Feb 2007 04:32:05 -0500 (EST)
  • References: <epp68i$cv0$1@smc.vnet.net>


$Version 5.1 for Microsoft Windows (October 25, 2004)

Hi Kristen,

the usage of & and #: f[#]& is an abbreviation for: Function[x,f[x]] 

with the default argument #. Therefore, Random[Integer,10]& is a 

function that returns, when called, a random integer between 1 and 10.

Array[Random[Integer,10]&,20] will call Random[Integer,10]&[x] with x 

set succesively to 1,2,..10. Note that in this case the argument is 

never used.

On the otherhand, Array[Random[Integer,10],20] will call 

Random[Integer,10][x]. This is a strange construct, the Head is: 

Random[Integer,10], evaluating to a random integer. The argument is 

still an integer from 1..10. We have e.g. 5[3]. This can not be 

evaluated any further.

Daniel



Kristen W Carlson wrote:

> Hi,

> 

> From Built-in Functions/Cases, here is this (undocumented?) usage of &

> without #:

> 

> 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

> 

> 

$Version



  • Prev by Date: file functions & FrontEnd`FileName
  • Next by Date: loglogplot
  • Previous by thread: Re: & without #
  • Next by thread: RE: & without #