Some More Thoughts on Syntax
This article is a thought experiment and if you are not interested in such things stop reading now.
Since writing yesterday's post, I got to thinking about references, boxing, and unboxing, and what role if any should any of this have upon a language. Look to OCaml as an example:
let foo = ref 2
Here we are using an explicit reference to an integer. We can say foo has a ref int type, and can pass around this reference as a value. The size of the integer is immaterial as the reference is of a known fixed size. This property of references can lead to significant size and performance increases when the referee is large or complex or multiply linked. To access the value at foo we write:
Linguistically speaking foo isn't even a pronoun. It serves much the same role as the word it, but it is not the it we are interested in. We are interested in "its value", which places it into the genitive. In the nominative foo as it is an opaque value defined almost entirely by its role of possessing a value.
This brings me back to the thing I'm thinking about, nested arrays. So let's assume we have a , message we can pass to an array that will generate a function which will return that array withthe function's argument appended to the end of it:
1 , 2 , 3
1,2 , 3
Now what if we start with an Array and attempt to append an array:
1,2 -> foo ;
foo , 3
So foo is an Array, and should append 3 to the end of it 1,2,3. Now what happens if we have an array and another array what should happen:
1 , 2 -> foo ;
3 , 4 -> bar ;
foo , bar
Do we get 1,2,3,4 or [1,2,3,4] or 1,2,[3,4] or even [1,2,3,4]? What do you expect?
If foo is term equivalent to 1 , 2 and bar is term equivalent to 3 , 4 then you expect:
foo , bar = 1 , 2 , 3 , 4
Which is what one would get with a simple term rewriting engine. This isn't bad it just means we've made it nigh impossible to construct nested arrays with only this syntax and grammar. We need to concoct a Notion of reference that can stand in for an array value in a list context. This is exactly what Perl did with Array refs, and why all refs in Perl require a grammatical dereferencing via the @ operator.
What if we go down the other dark alley and treat foo and bar as explicit references:
foo , bar = 1,2,3,4
In this case we are using notation to indicate a referenced value. This allows us to construct complex shapes via symbolic+explicit reference but it means that , on a reference behaves differently than , on the array itself. This means we need a dereference operator say * which seems popular for this purpose so:
foo * , ( bar * ) = 1 , 2 , 3 , 4
And my look at the horror! Not only have we revisited Python (Python Revisited?). But also had to invoke a nested context to dereference prior to passing to the Array , operator. Which begs a silly question "Does Array , ref dereference ref or does it append the reference?".
So the result of all this is one has to step back and remember Arrays are objects made up of objects. They are collections of objects.