Some Thoughts on Syntax

This post is a digression on developing a mental model for a object message syntax for object creation. If you aren't interested in a thought experiment stop reading now!

1 , 2 , 3

In this case sending , to 1 generates an Array with one element 1 and subsequent application of , to the array alternately generates a function which concats it's argument to the array and returns the array with the value appended. So here comma to a Number or String or Array produces an Array.

'foo' : 2

Could produce an Object  foo : 2 and would give us a syntax for generating an array of bindings

'foo' : 2 ,

Would return an Array {foo:2} and we could keep using , to append to this array:

'foo' : 2 , 'bar' , 4

Which would produce {foo:2},'bar', 2 which would be consistent. If we add a : method to array we could produce objects of the form:

'foo' : 2 , 'bar' : 4

Which would produce {foo:2},{bar:4} which looks a lot like an assoc list in Lisp, which is a reasonable approximation of a JavaScript object.

'foo' : 2 , 'bar'

Produces an array {foo:2},'bar' which is an intermediate state from the standpoint of an object construction syntax but exactly what one might expect!

So in this syntax, the operation of : on an array converts the last element to the key of a KV pair.

We can use () to capture the value of an expression:

'foo' : ( 1 + 1 )

And the nested expression would evaluate and be passed to the continuation : function. We can use this to bind partially applied functions as well!

'negate' : ( 0 - )

Which isn't terribly clear