The odd thing about purpose is that there doesn't seem to be a science of it. But "purpose" is a fairly basic explanatory concept, which we use to explain many things, and science is about explaining things, so there really should be.
I am going to define "purpose" as follows:
A purpose is an explanation where the thing being explained comes before the thing explaining it.
In other words, something is a purpose if it explains the occurrence of events that happen before the purpose. This is contrary to all other forms of explanation, where the explanation or cause occurs first, and the thing being explained by the cause comes after the cause.
Here are two simple examples, one with a purposeful explanation, and one with a normal causal explanation:
Because the cause and effect of purpose is the "wrong way round", purpose-based explanations are often regarded as "unscientific". But purpose is a concept that we use to explain many things in everyday life, so it is a bit dubious to imply that it is an unscientific concept, since this would mean either that our everyday thinking was completely unscientific, or that there was some legitimate and relevant field of understanding in which scientific thinking was not applicable.
An alternative approach is to look for a scientific theory of purpose.
The biggest breakthrough in the scientific study of purpose was Charles Darwin's theory of evolution by natural selection. Darwin did not (as far as I know) categorise his theory as a theory of purpose, although he did certainly used the word "purpose" quite often in his writings, when referring to the purposes o particular structures and behaviours of living organisms. But we will see that Darwin's theory was an important step on the journey towards a general theory of purpose, because he identified the importance of selection.
It is the combination of selection and persistence (or repetition) of the thing being selected for which allows the "reversal" of causality found in an explanation based on purpose. For example, we would say that the purpose of a giraffe's long neck is to enable it to reach the highest leaves on the trees (where reaching the leaves comes after the growth of the long neck). Natural selection explains that the past success of giraffes with long necks that could get more to eat resulted in an increasing proportion of the population of giraffes having the genes for developing a long neck. The persistence part of the explanation is when the genes of the previous generation of successful long-necked giraffes are passed on to the next generation of giraffes.
So although at first sight it appears that it is the future success of the giraffe in getting leaves which explains the growth of its long neck, it is really the past success of the giraffe's ancestors which explains the growth of its neck, as determined by genes for a long neck, where those genes were passed on to the current giraffe from its long-necked ancestors.
The success of this type of explanation can suggest that all observations of purpose in the real world are to be explained by a hypothesis of selection, and that perhaps there is no other possible explanation. By supposing that selection is the only possible explanation of purpose, we avoid having to believe in any kind of magical reversal of causality.
The purposeful nature of structure and behaviour of living organisms is the primary example of purpose found in the world, and as long as those structures and behaviours are determined genetically, the theory of evolution by natural selection suffices to explain their purposefulness. But there are some functions perfomed purposefully by living organisms which are not directly determined genetically, so that natural selection cannot directly explain where the purposefulness of those functions comes from. It turns out that we have to discover some other selection mechanism, one which typically operates within one individual organism, and within that organism's lifetime.
One simple example is that of antibodies. The cells that present antibodies breed and mutate within the body of an animal, and they are selected for according to their usefulness in destroying foreign organisms that appear to pose a threat to the animal. When an animal has a certain disease (like, say, a strain of influenza), it develops antibodies specific to that disease organism, and we can say that the purpose of those specific antibodies is to attack that specific disease organism. The purposefulness of the antibodies is explained by the selection process involved in creating them. The selection mechanism itself has a purpose, which is to foster the development of useful antibodies, and this mechanism is determined genetically, and the selection mechanism which explains that purpose is that of natural selection.
So we have two layers of purpose and selection: natural selection explains the existence of a purposeful mechanism for selecting antibodies, which causes the antibodies to have the purpose of attacking specific disease organisms.
Something similar but somewhat more complicated applies to learning. Many learned behaviours are purposeful, and presumably some selection mechanism is involved in learning them. The first attempt to explain learned behaviours via a selection mechanism was the theory of operant conditioning as discovered by BF Skinner. This theory has been somewhat discredited, and is now seen to be over-simplified in its explanation of how animals (and people) learn, but it does highlight the need for a selection mechanism to explain the purposefulness of learned behaviour. According to the theory, particular behaviours in particular circumstances are selected for or against according to the immediate short-term consequences of those behaviours which are interpreted as rewards and punishments. For example, the behaviour of a hungry rat in a box pushing levers would be rewarded if the behaviour caused food to appear, and the rewarding effect of satisfying hunger would cause that behaviour to be selected for, so that it was more likely to occur in the future.
One objection to this theory, in the human case at least, is that our heads already seem to be full of complex processes for making decisions about what to do or what not to do, and these processes operate in more complicated ways than just automatically selecting randomly initiated behaviours as a function of immediate rewards and punishments. Are those purposeful processes to be regarded as genetically determined? And if they aren't, what selection mechanism do we invoke to explain their existence, if we think operant conditioning is too simple? And is there any mechanism at all that can select for behaviours as a function of their long-term consequences? (It is a relevant point that non-human animals are somewhat more short-term in their outlook than humans, and it is also relevant that humans are often more short-term in their outlook than they think they should be. Both these points suggest that there is some intrinsic difficulty in learning behaviours which are purposeful in terms of achieving long-term goals.)
I said that the theory of operant condition has been rejected as being too simplistic, and fails to account for many of the facts. But I think there is more to its rejection than this. It's not just that it's an unsatisfactory explanation of purpose, it's that many people don't want there to be any explanation of purpose in terms of non-purposeful mechanisms. Those people are all too happy to discredit the idea of any explanation based on a selection mechanism.
A similar rejection of selection-based explanations of purpose happens when religious believers reject Darwin's theory of evolution by natural selection. The religious view is that purpose comes into the Universe from an external source of purpose, i.e. God, and trying to explain purpose in terms of non-purpose is not needed and not desired.
Returning back to a scientific point of view, we can see that even if operant conditioning is not a satisfactory or complete explanation of how behaviour is learned, the full explanation, whatever it is, has to include some kind of selection mechanism. In an earlier article, I suggested that some of the basic rules of thinking in our brain are acquired neither genetically nor from experience, but are received directly from other people, especially from our parents. This implies a mechanism for uncritically accepting certain types of information under at least some circumstances. It also implies that the relevant selection mechanism is the long-term reproductive success of people as a function of their culturally acquired world view, and this explanation is quite analogous to the explanation of how natural selection acts on genetic information.
People often wonder what the Meaning of Life is, and a common interpretation is that the word "meaning" in this question really means "purpose". A simple biological answer to the question is that the purpose of life is long-term reproductive success, but this answer isn't quite what people are looking for, perhaps because the intended meaning of the word "life" in the question is something slightly different from its straightforward biological meaning, and "life" really refers to a person's mental life.
I have already shown that the purpose of human thoughts and actions is a different layer of purpose with a different selection mechanism, and we don't even know exactly what that selection mechanism is or what it selects for or against. But we can at least see that questions about the purpose of our thoughts and actions are non-trivial questions, and those questions won't be properly answered until we do understand the relevant selection mechanisms.
In the meantime we have to waffle somewhat around our ignorance, and give an answer something like the following:
The (psychological) purpose of life is for the internal states of our mind to be selected by whatever selection mechanism it is that acts on our internal states of mind, where selection is applied according to the consequences of the thoughts and actions which are consequent upon those internal states of mind, and according to whatever other consequences are taken into account by said selection mechanism.