To answer your title question "Does any programming language use variables as they're in maths?":
C, C#, Java, C++, and any other C style language use variables in the way they are used in math.
You just need to use == instead of =.
If I take your original
root(square(x)) = abs(x)
Then I can translate that into C# directly without any changes other than for the syntax.
Math.Sqrt(Math.Pow(x,2)) == Math.Abs(x)
This will evaluate to true for any value of x as long as x squared is less than the max for the data type you are using.
(Java will be grossly similar, but I believe the Math namespace is a bit different)
This next bit will fail to compile in C# because the compiler is smart enough to know I can't assign the return of one operation to another operation.
Math.Sqrt(Math.Pow(x,2)) = Math.Abs(x)
Immutability has nothing to do with this. You still need to assign the value in an immutable language and it's entirely possible that a given language may chose to do this by using = as the operator.
Further proving the point, this loop will run until you exhaust legal values of x and get an overflow exception:
while (Math.Sqrt(Math.Pow(x, 2)) == Math.Abs(x))
{
++x;
System.Console.WriteLine(x);
}
This is why mathematicians hate the use of = for assignment. It confuses them. I think this has led you to confuse yourself. Take your example
y = (x**2)**.5
x *= 2
assert y == abs(x)
When I turn this into algebra, I get this:
abs(2x) = root(x^2)
Which of course is not true for values other than 0. Immutability only saves you from the error of changing the value of x when you add extra steps between evaluating the Left Hand Side and Right Hand Side of the original equation. It's doesn't actually change how you evaluate the expression.
Setting aside the question of the definition of object oriented programming the question becomes one of "are there languages which use composition only and have no tools for inheritance?"
The answer to this is quite simply "yes". In go, there are no way to do inheritance as one classically thinks of it. One can embedded an object in another object and the extend that object. From Object Desoriented Language (github mirror):
type Person struct {
Name string
}
func (p *Person) Intro() string {
return p.Name
}
type Woman struct {
Person
}
func (w *Woman) Intro() string {
return "Mrs. " + w.Person.Intro()
}
You've got a person struct that has a Name which is a String. It has a public function called Intro which returns the name. The Woman struct also has a function for Intro which accesses the strut embedded in it. And so one can fulfill the intentions of inheritance by using composition only.
More on this can be seen at GoLang Tutorials: Inheritance and subclassing in Go - or its near likeness.
So yes, it is possible to have an OO language without inheritance, and one does exist.
Within go this is known as embedding and gives enclosing structures the ability to access the embedded fields and functions as if it had them too - but it's not a subclass. The design philosophy can be found in the Go FAQ: Why is there no type inheritance?
Best Answer
Assuming a url of
http://example.com/hello/world
, and the following.htaccess
:router.php
, an overly simplistic router, would be:That's a pretty standard practical use of variable variables. Neat trick, but you should be extremely careful when using it, over/abusing it will certainly lead to horribly unmaintainable code.
Disclaimer: The code presented in the answer is only intended to illustrate the use of the feature. It does not cover proper design, security, maintainability, or sanity. Do not use.