MathGroup Archive 2009

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

Search the Archive

Re: Bug, quirk or expected behavior of Slot[]?

  • To: mathgroup at
  • Subject: [mg101805] Re: Bug, quirk or expected behavior of Slot[]?
  • From: earthnut at (Bastian Erdnuess)
  • Date: Fri, 17 Jul 2009 05:06:18 -0400 (EDT)
  • References: <h3n5q6$2bm$>

Salvatore Mangano <smangano at> wrote:

> Someone on the "Linked In" Mathematica User group pointed this out to me:
> In[26]:= Clear[y]
> Function[Module[{y=0},#===y]][y]
> Function[Module[{y=0},#1===y]][y]
> Function[t,Module[{y=0},t===y]][y]
> Out[27]= True
> Out[28]= True
> Out[29]= False
> It leads me to believe # is more like a placeholder for macro-like
> substitution than a formal parameter like t.
> Thoughts?


  In[_]:= Function[ t, Module[ { y = 0 }, t === y ][ y$ ]
  Out[_]= True

In the help to Function is written:

  - The named formal parameters x_i in Function[ { x_1, ... }, body ]
    are treated as local, and are renamed x_i$ when necessary to avoid
    confusion with actual arguments supplied to the function.

  - Function constructs can be nested in any way. Each is treated as a
    scoping construct, with named inner variables being renamed if

It might be the case that Function[ vars, body ] is considered to be a
scoping construct, but Function[ body ] not.  (Since '#'s don't count as
'named inner variables' and so don't need to be 'scoped'?)

And as scoping construct it makes Modules -- another scoping construct,
to rename all local variables. ?


  • Prev by Date: Re: Modify variable names in a loop
  • Next by Date: Demonstrations Surpass 5,000
  • Previous by thread: Re: Bug, quirk or expected behavior of Slot[]?
  • Next by thread: another Epilog LogPlot problem