Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #11014 > unrolled thread

Re: can one make local symbol in a pure function?

Started by"djmpark" <djmpark@comcast.net>
First post2012-07-21 03:40 +0000
Last post2012-07-21 03:40 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: can one make local symbol in a pure function? "djmpark" <djmpark@comcast.net> - 2012-07-21 03:40 +0000

#11014 — Re: can one make local symbol in a pure function?

From"djmpark" <djmpark@comcast.net>
Date2012-07-21 03:40 +0000
SubjectRe: can one make local symbol in a pure function?
Message-ID<jud8bs$j0f$1@smc.vnet.net>
Make the body of the Function a Module or With statement?


David Park
djmpark@comcast.net 
http://home.comcast.net/~djmpark/index.html 


From: Nasser M. Abbasi [mailto:nma@12000.org] 



I was learning a bit about pure functions.
Suppose we have this toy example:

-----------------
Clear[f, x]
f[x_] := Module[{a = 2}, x^a]
lst = {1, 2, 3};
Map[f[#] &, lst]
-------------------

---> {1, 4, 9}

Now I'd like to define the pure function in-line, using the Function[]
syntax, but at the same time be able to make a local symbol 'a' like I did
when using Module. But the syntax does not allow one to do that. There is no
place to define it:

------------------
lst = {1, 2, 3};
Map[Function[{x}, x^2], lst]
----------------

---> {1, 4, 9}

So if someone wants to make a temporary symbol to use for temporary
calculation inside the pure function, like 'a' in this example, and at the
same time not have it be global symbol, then one must use a Module? I can
write

---------------------
lst = {1, 2, 3};
Map[Function[{x}, a=2; x^a], lst]
----------------------

But now 'a' is global, while when using Module it was local.

Any way to make local symbols in a pure function like with Module?

thanks,
--Nasser

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web