## Introducing Ambi

I love RPN calculators and have been experimenting with how it may be possible to extend the RPN stack style into a structured programming language. Ambi is the result. Here is Ambi for the factorial function and an invocation:

function; ! ; seq ; import $n = ; ifelse;$n 1 eq; 1 export; $n 1 - !$n * export; 

 

5 ! .;

(The 'import' operator pops the top stack item from the calling context and pushed it onto the expression's stack. 'export' is the converse pushing the top of the expression's stack back out into the calling context's stack.)

Notice that the program is written using Polish (prefix) notation without any brackets and individual expressions are written in Reverse Polish (postfix) notation. Actually, Ambi doesn't care whether the programmer writes the program (and individual expressions) in prefix or postfix notation. Here is the exact same program written in postfix.

 import $n = ;$n 1 - ! $n * export; 1 export;$n 1 eq; ifelse; seq; ! ; function 

Ambi is an open source language and has been implemented in browser-based Javascript and an interpreter and documentation lives at http://www.davidpratten.com/ambi There are lots of example programs there that can be loaded into the interpreter just by clicking on them.

Ambi owes a debt to Forth, RPL and to CAT. CAT (and earlier) JOY elected to make the composition operator implicit, whereas in Ambi it is made explicit in the 'seq' operator.

Your observations, suggestions, and/or critique are welcome.

David

## Comment viewing options

### Why?

What's your motivation for supporting both PN and RPN?

I think Bjarne Stroustrup has proposed something similar to your double sided comment scheme, though he chose the reverse symbol "\\" for pre-comments - presumably to avoid some ambiguity.

Also, have you considered restricting valid identifiers to palindromes?

### Why Ambi supports both PN and RPN

Good question.
Ambi was motivated by my desire to generalise RPN arithmetic 'goodness' to a full programming language. However I noticed that when I started writing multi-expression programs in postfix(RPN) style that my head hurt. It turns out that the "Zen" of RPN surfaced when I started writing the programs using PN and the individual expressions in RPN. However, others' brains may be wired differently and so I decided to leave the PN / RPN decision to the programmer.

### Ambi and Stroustrup's modest proposal

Ambi programmers can write either PN or RPN comments.

Ambi is unlikely to advance the art in regard to whitespace overloading. It does however provide a useful browser-based and extensible RPN calculator and an accessible tool for exploring programming ideas.