WaltP
Posting Sage w/ dash of thyme
10,505 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
Basically, it is a block of code identifies with a name.
kbshibukumar
Junior Poster in Training
65 posts since Jan 2009
Reputation Points: 12
Solved Threads: 8
Basically, it is a block of code identifies with a name.
Not completely.
Every functions has a domain and a co-domain and its definition.
The domain is the valid range of numbers that can be accepted.
The co-domain is the valid range of numbers that the function can map to.
The definition of a function gives some explicit way to convert the input into an output.
For example, consider the function F: R - >R, where F(x) = x*x.
The function domain is R( all real numbers), the function co-domain
is R(all-real numbers) and its definition is F(x) = x*x.
Now in code its very similar :
int F(x){ return x*x; };
Now the domain is implicitly stated as all real numbers. So we do not check if x is an imaginary numbers( that and we can't anyways).
The co-domain is all real number and is implicitly stated by the return type of the function, int. The definition is x*x, which is in the
body of the function.
So that is a function.
It has a domain, the valid range of numbers the function can accept.
It has a co-domain, the valid ranges of numbers the function can map to or "spit out".
It has its rule, or its definition.
firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608
firstPerson's definition is more like one that might be used in a formal mathematical setting. Check out the second paragraph of http://en.wikipedia.org/wiki/Functional_programming for a comparison of the two definitions. I'm sure we could argue about the semantics of what constitutes a function (like "is a void function really a function by one definition or the other?") but I think WaltP offered the best approach as it seems the OP was just looking for basic info...
jonsca
Quantitative Phrenologist
5,621 posts since Sep 2009
Reputation Points: 1,165
Solved Threads: 581