Niue updates

Added two new words to Niue – ^ and get-r. ^ raises a number to the power of another:

4 2 ^ .
=> 16.0
673874883784677373 6 ^ .
=> 9364306491992936597418307443160066797807428695875
   3713230115132798366662566814067348891103643839017799209689

get-r is similar to get, but it removes the key-value mapping from the stack:

'x 10 'y 200
'x get-r .s
=> y 200 10

get-r can be used to emulate keyword arguments:

[ 'x get-r 'x ;
  'y get-r 'y ;

   x y / . ] 'd ;

'x 123.45 'y 34 d
=> 3.6308823529411764

( order of values on the stack does not matter. )
'y 34 'x 123.45 d
=> 3.6308823529411764

Also wrote a short tutorial that highlights the syntax-less nature of Niue.

Crazy sort

Want to twist your brain by sorting in a stack language? Ok. First we need to define a function to put the minimum value on top:

[ dup 'm ; [ at dup m < [ 'm ; ] if [ , ] else ] len 1 - times m ] 
'min ;

Next we need a secondary stack to hold the intermediate sorted values. Let us create a child virtual machine to keep track of the secondary stack, so that it can respond to a get message and push the sorted values back to the main stack:

{ >> dup 'get equals [ <<< ] when } 
'sorted ;

We now have a function to find the minimum value on the stack and a virtual machine to keep track of the sorted elements, implementing the simple selection sort algorithm is just another one-liner:

[ [ , min dup sorted remove ] len 1 - times 'get sorted reverse , ]

'selsort ;

So there is our “stack sorter” in three lines!

Tests:

4 2 3 1 6 7 selsort .s
=> 1 2 3 5 6 7
20 100 45 selsort .s
=> 20 45 100 
1 2 3 4 5 selsort .s
=> 1 2 3 4 5

FP in Niue

Started adding Backus' FP primitives to Niue. Progress is slow, sleep is overtaking me :–). A stack language is an apt vehicle for FP as you get function composition and implicit argument passing for free. Here is the famous inner-product example in Niue:

[ transpose '* apply-to-all '+ reduce ] 'inner-product ;

1 2 3 6 5 4 inner-product .
=> 28

This is how the call to inner-product got expanded:

1 2 3 6 5 4
transpose ( => 1 6 2 5 3 4 )
'* apply-to-all ( => (1 * 6) (2 * 5) (3 * 4) => 6 10 12 )
'+ reduce ( => (6 + 10 + 12) => 28 )

An interesting “language implementation exercise”!

Niue available for consumption

The Niue language was made available for public consumption on Mar 23rd.  A release is yet to be made but this early announcement has met with favorable response.  Many have tried the language and came back with comments and bug reports.  Thank you all.  In a short time, Niue made its presence felt at many interesting places on the web:

  1. reddit
  2. rosettacode 
  3. Slava Pestov's twitter

Thanks to the guys who joined the Niue users group and made it come alive!

New projects, new ideas

Started on Cirrina (a MapReduce framework for Common Lisp) and Niue (a Forth like concatenative language for the JVM). Created the git repositories

Compiled and ran the Inferno OS using my Linux laptop as a hosted environment. A great but surprisingly underrated platform, dangerously ignored even by the "Cloud Computing" crowd. Planning to write a Lisp for the Dis VM.

So many ideas, so many things to learn, so much to do and such a great dearth of time!