Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*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 2004

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

Search the Archive

Re: Defining a function in module problem?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg46005] Re: Defining a function in module problem?
  • From: drbob at bigfoot.com (Bobby R. Treat)
  • Date: Mon, 2 Feb 2004 05:20:55 -0500 (EST)
  • References: <bvhpvs$8dh$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

The better questions are, "Why write it that way?" and "What's the
philosophy behind doing that?"

This is much simpler and does what you apparently want:

a[x_]:=x/3

As for your question, it seems to me that g = z/3 involves a different
z (a Global variable) than the one in Function[z,...] (it's a scoping
issue, and precisely what we should expect from using Function). Hence
f isn't a function of its argument, and that's why you get the result
you see.

Bobby

jflanigan at netzero.net (jose flanigan) wrote in message news:<bvhpvs$8dh$1 at smc.vnet.net>...
> why does this
> 
> a[x_] := Module[{f, g}, g = z/3; f = Function[z, Evaluate[g]]; f[x]]
> 
> produce
> 
> a[1] = z/3
> 
> instead of
> 
> a[1]=1/3
> 
> I don't understand the philosophy here.
> 
> thanks in advance.


  • Prev by Date: Re: Defining a function in module problem?
  • Next by Date: Simple Differentiation?
  • Previous by thread: Re: Defining a function in module problem?
  • Next by thread: Re: Defining a function in module problem?