Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'how do i make one function from lots of code?' topicStudent Support Forum > General > "how do i make one function from lots of code?"

< Previous CommentHelp | Reply To Comment | Reply To Topic
Author Comment/Response
jason
09/24/11 10:32am

I don't know if there is a way to define a normal function inside a Module. But you can use a pure function.

To use a pure function of one variable, you put # in place of the variable. For functions of two or more, you use #1, #2, etc. Then you need to put & directly following the pattern you set to indicate it is a function.

I'm also using the shorthand notation f/@x for Map[f,x].

giantfunction[x_] := Module[{a},
a = (# + 1) & /@ x;
#^2 & /@ a];
giantfunction[{1, 2, 3, 4}]



URL: ,

Subject (listing for 'how do i make one function from lots of code?')
Author Date Posted
how do i make one function from lots of code? littledrifty 09/22/11 3:55pm
Re: how do i make one function from lots of code? jason 09/24/11 10:32am
< Previous CommentHelp | Reply To Comment | Reply To Topic