Original Post
In a theoretical experiment in language creation, I'm stuck looking for a simple yet useful syntax that expressed these intended semantics: objects are non-mutable, the only possible operation is to create a new object or a modified copy of an old object. In addition to that, the language uses expression semantics, rather than statement semantics: nothing has a side-effect, so everything is an expression, including the body of a function. The main operation performed in this part of the language is the modification of the fields of these objects. Below is the current syntax for swapping objects in a pair, using the creation of a new object, and the modification of one:
compact Pair { first : int; second : int }
fun (swap_1:Pair (pair:Pair))
(new Pair
(first pair.second)
(second pair.first))
fun (swap_2:Pair (pair:Pair))
(let t pair.first
(## (pair.first pair.second) (pair.second t)))
The syntax appears pretty clear to me, but there might be usability issues tied to the usage of the ## command. What do you think? Do you have any other syntax suggestions that are compatible with the semantics, but would be easier to manipulate?