sean butler

VO: When a Callable is just a value, Custom Operator Prescidence is and Easy Win

On VO, a dynamic programming language with an interesting set of features.

Recently updated vo. We now have infix/prefix/postfix syntax. This where a programmer can set the position of the caller identifier relative to the parameters at function declaration time. It work like this:

_ add _ = @(a, b) { a + b }

That defines add as an infix operator. Write 3 add 4 and you get 7. You can also do prefix:

incr _ = @(a) { a + 1 }

incr 5    // 6

Or postfix:

_ double = @(a) { a * 2 }

5 double    // 10

The _ shows where the operands go. Everything to the left of the name is a left operand, everything to the right is a right operand. The parser registers it and rewrites call sites accordingly — x add y becomes add(x, y) before anything is evaluated.

This isn’t operator overloading. It isn’t a macro system. There is no operator keyword, no special declaration form. The function on the right-hand side is completely ordinary. The same @(params) { body } you use for everything else. You can still call add(3, 4) the normal way. Nothing about the function changed. In practice you just told the parser that there is an additional way to invoke it.

We still dont have the ability to set prescidence for multiple operators like brackets, braces or similar. Maybe soon.

Part of the reason this works cleanly is that in VO, because of one of the early design decisions. A callable is just a value, declaring a callable is binding it to a value. There is no def statement, no function keyword, no distinction between defining a function and binding any other kind of value. So in VO the prefix/infix/postfix choise is states as a property of the binding, not of the thing being bound.

( see also: programming-languages interpreters prototype-based minimalism internationalization vo decolonialism )