Ambi – streamlined – loses SEQ operator

Ambi is proving to be a great extensible RPN calculator. Applying the ‘zen’ of RPN to programming fun!

Enjoy the new release of Ambi.

This week I have discovered that the seq operator is not necessary.  Initially, I thought that seq would be necessary, however it turns out that the other lambda operators are sufficient.  So we now can write an interative approximator of cuberoot in this way …

function; root3;
  dowhile;
    import dup $n = $guess =;
    $guess $prev = $n $prev sq / $prev + .5 * $guess =;
    $guess $prev - abs .000000001 >;
    $guess export ;
125 root3 .

Not a seq in sight!   And we may rewrite the function as a recursive function this way …

function; inner-root3;
 if;
  import $n = import $prev = $prev $n $prev sq / + .5 * $guess = $guess $prev - abs .000000001 >;
  $guess $n inner-root3 $guess =;
  $guess export;

function; root3;
  import dup inner-root3 export ;

100 root3 .

In addition the current release adds the ++ and increment and decrement operators.

Reverse Polish Notation Language

I love RPN calculators.  My favorite is Hypatia which I use regularly for calculations.  I love being able to order my calculation to avoid brackets and being able to enter a list of numbers and add them up with a single command:

hy 12 23.4 43 94 3 d SUM

Now I am wondering about a full computer language built from the ground up as an RPN language?

A bit of googling led me to RPL or Reverse Polish Lisp which is close.  I wonder if this direction has been explored in other languages.

I am imagining a language where assignment is pretty straight forward (with explanatory pseudocode comment):

1 a = # a = 1

boolean expressions are just regular RPN:

a 1 + b > # a + 1 > b

and an if control structure would look like:

; bf ; bt ; a if # if a then bt else bf;

the meaning of the “;” token is to push following tokens (until the next structural token) unevaluated onto the stack as a single entry.  The if token evaluates the top stack entry (a) and then evaluates either the second (bt) or the third (bf).

A do while loop would look like this:

; b ; a dowhile # do b while a;

The dowhile token evaluates the second stack entry (b) and then the first (a) and repeats until a is false.

A key of RPN expressions is that there are no brackets required – by analogy in a RPN language there would be no nested statements!

Open question.  Can this idea be developed into a usable programming language?

Fun with Monad?

Remember command.com and .bat files? Still using them? I recently downloaded Microsoft’s new command shell (available here). The key idea seems to be to make 99% of the internals of a MS Windows based computer accessible to a command shell. Whereas the Unix tradition of shells have commands linked together by consuming and producing text – in Monad commands consume and produce objects. [Read more…]