Felix Programming Language

Authors : erickt : May 2009

flxc: A new driver that will support an interactive felix

posted on May 26, 2009 - 01:36 PM PDT by Erick Tryzelaar

I just committed 6f6559 that adds support for an experimental new driver called flxc that will support a REPL. It's got a ways to go, but here's what it can already do:

# build/debug/bin/flxc -I build/debug/lib --import nugram.flxh --import flx.flx
>>> 1;
... PARSED:    call 1 ();
... EXPANDED:  call 1 ();
... DESUGARED: call 1 ();
>>> (1 + 2) * 3;
... PARSED:    call 1+2*3 ();
... EXPANDED:  call 9 ();
... DESUGARED: call 9 ();
>>> val x = 5;
... PARSED:    val x = 5;
... EXPANDED:  val x = 5;
... DESUGARED: val x: typeof(5);
x := 5;
>>> fun foo (x:int) (y:float) = {
        val z = x + 1;
        var w = y * 2.0f;
        val s = "hello ";
        return s + "world!";
    }
... PARSED:    fun foo(val x: int) (val y: float): <none>
{
  val z = x+1;
  var w = y*2.0f;
  val s = "hello ";
  return s+"world!";
}
... EXPANDED:  fun foo(val x: int) (val y: float): <none>
{
  val z = (add (x, 1));
  var w = (mul (y, 2.0f));
  val s = "hello ";
  return (add (s, "world!"));
}
... DESUGARED: generated curry fun foo(val x: int): <none>
{
  body _rqs_foo = c"" requires _rqs_<input>;
  fun foo'2(val y: float): <none>
  {
    body _rqs_foo'2 = c"" requires _rqs_foo;
    val z: typeof((add (x, 1)));
    z := (add (x, 1));
    var w: typeof((mul (y, 2.0f)));
    w := (mul (y, 2.0f));
    val s: typeof("hello ");
    s := "hello ";
    return (add (s, "world!"));
  }
  return foo'2 of (float);
}

It even supports syntax extension:

>>> syntax foo {
        requires statements;

        svar_def := "foo" sdeclname = sexpr ";" =>#
            """
            `(ast_var_decl ,_sr ,(first _2) ,(second _2) none (some ,_4))
            """;
    };
... PARSED:    {/**/;}
... EXPANDED:
... DESUGARED:
>>> open syntax foo;
... PARSED:    {/**/;}
... EXPANDED:
... DESUGARED:
>>> foo x = 5;
... PARSED:    var x = 5;
... EXPANDED:  var x = 5;
... DESUGARED: var x: typeof(5);
x := 5;

read comments