esolang

Vafix

Two operators, and each one is dyadic, monadic or niladic. Where it stands decides which.

A, 2019 · Turing complete: no · ●○○ easy · esolangs.org

Tested with 5 known programs · Test method

Run it

Expected: 1+1+1 3

The idea

The user A made Vafix in 2019 as a thought experiment about APL, where a function takes one argument or two. Vafix adds a third way, no argument at all. So + adds, keeps a number or is the number 1, and - subtracts, negates or is -1. It is meant to be as confusing as anyfix.

Read the story

The specification says Vafix guesses each operator from the right, trying dyadic first, then monadic, then niladic. Its interpreter does it by position alone. The last place is niladic, the one before it dyadic, and so on in turn. When the length is even, the first place is monadic and applies to everything after it.

The machine

CharDyadicMonadicNiladic
+AddKeep1
-SubtractNegate-1

The interpreter drops every bracket before it starts, so brackets change nothing. A run prints the infix sum it built and then its value, as the interpreter does with Python's eval. The specification calls Vafix backwards in the spirit of APL, but eval works the sum from the left, so +-+++ gives 1-1+1 and 1 where APL would give -1. This implementation follows the interpreter.

The specification says any other character is a nilad of value 0. The interpreter instead copies it into the sum, or leaves it out in a niladic place. This implementation does the same, works out digits, blanks and line breaks as Python does, and stops with an error on any other character in the sum.

Example

The walk through +++++.

The walk through +++++. From the right the places are niladic, dyadic, niladic, dyadic and niladic.

The two examples, -10 and 7 + (-5).

Expected: -1+-1+-1+-1+-1+-1+-1+-1+-1+-1 -10
Expected: 1+1+1+1+1+1+1+-1+-1+-1+-1+-1 2

With four characters the first one is monadic. The specification writes -(-1+1) as -(-++) and golfs it to --++, and both give the same sum.

Expected: -(-1+1) 0
Expected: -(-1+1) 0

Patterns it teaches

  • Hostile design: the arity of every operator has to be worked out from where it stands.

Further

APL-like

Declarative paradigm

Write your own in Run Convert a program from Vafix

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: vafix.

Command line

shib run vafix -e '--++'
shib manual vafix

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/vafix.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org