It depends on exactly what you mean
I can see three possibilities for what you might be asking about here.
If the problem is that, in a language like C for instance, it's not possible to write things like this:
int f(int x) {
return g(x + 1);
}
int g(int x) {
return x + 1;
}
because the compiler will complain that it doesn't know what g
is during the definition of f
, then the answer is very much yes. Many languages allow functions to be defined out of order, although often it comes at the cost that calls to nonexistant functions won't throw an error until they actually happen while the program is running. Python falls in this group for instance, along with most if not all lisp languages.
If, on the other hand, you want the same to apply to variables - allowing programs like:
x = y + 1
y = 2
Then the answer is also yes, but it comes with even stronger caveats. What you're looking for is a purely or nearly purely functional[1] language like Haskell or Prolog, which can achieve the property you seem to be asking about by virtue of not allowing any modification to a variable once it's been defined. This means the language doesn't have to care where the definition took place - since order doesn't matter, it can shuffle the lines about (kind of) freely. The following is a valid Haskell program that prints 3
:
x = y + 1
y = 2
main =
print(x)
I don't think it's possible to have what (I think) you're asking about and also allow variables to be modified, because if a variable can be modified then the language must have some concept of time in order for there to be a 'before' and 'after' changing it.
[1] Strictly speaking, being a functional language is unrelated to allowing definitions out of order in this way. What is needed is not allowing variables to be changed after definition, which is one part of functional programming but not all of it. However, I don't think any general-purpose language that doesn't allow variables to be updated wouldn't describe itself as at least a bit functional.
Ideally, the language could be designed to compile the high-level, intuitive instructions into the precise order.
You are assuming the work has to be done at compile time. I work with Prolog and other models of problem solving and in many cases the work is done at run time and not at compile time. While quantum computers is not something I do, your question seems to have touch points with quantum computing. $\endgroup$