Wednesday, February 20, 2019

Unfortunate

Zero-arity combinators often lead to weird behavior and I guess should, in general, be avoided. To boil it down to one example:


[ X Y -> Y X | -> 0 ] 1 2 ==> (2 1)

But

let F = [ X Y -> Y X | -> 0 ] in F 1 2 ==> (0 1 2)

The discrepancy is unfortunate but completely correct according to the operational semantics. In the first case, a lambda expression is applied to its arguments, then reduced; in the second case, the lambda expression is reduced, then applied.

It's unfortunate but I think I'll keep it.

Thursday, January 17, 2019

Log 011719

Right, so after some hacking, three things are now on my TODO list.

  1. Rewrite the Sudoku solver.
  2. Fix a renaming bug.
  3. Implement `eval` correctly.
The Sudoku solver is a hack. It is a rewrite of a solver I once wrote in OCaml. It has poor performance since inequalities aren't eliminated leading to way too much work and it also doesn't make use of Egel very well. It could all be done way more principled.

The renaming bug is due to that I tried to avoid renaming completely in the interpreter for performance reasons but, as it turns out, can't.

The two previous tasks are not too difficult. `eval`, however, will need the introduction of fine-grained locking on internal data structures and the implementation of a pure term evaluator.

Problems are that `eval` may at any point change the state of the interpreter, be called recursively, and be called from different threads.

I.e, `eval "eval \"[X->X\"" 1` are examples I am looking at. Guess I better start off with the first two tasks, though.

Tuesday, January 15, 2019

Log 011519

Right, so I am back after a long break to programming on Egel. Last I remembered, I got stuck on implementing basic input/output routines, decided I probably need to support the whole C Posix interface, which also meant having bytes as primitive types, and subsequently abandoned the whole project.

Not sure what I've been doing in the intermediate time. It involved a lot of Brexit posts and playing Magic Arena.

But I returned!

I decided that supporting Posix is overkill for now and just implemented basic reading and writing of Unicode strings to channels as primitives. Which isn't fine, all popular languages have byte IO as primitives too, but -ah well-, whatever.

I also implemented a small Unicode TCP transport for Egel. Combined with eval, that allowed me to write a small server which evaluates Egel expressions for anyone on port 5000.

# Testing Egel's Unicode TCP transport.
#
# The server spawns a listener for each incoming connection,
# evaluates input from there, and sends the result back.

import "io.ego"
using IO
using System

def listener =
    [ CHAN ->
        let IN = read_line CHAN in
        if eof CHAN then close CHAN
        else
            print "received: " IN "\n";
            let OUT = eval IN in
            print "sending: " OUT;
            write_line CHAN (blip OUT);
            listener CHAN ]

def spawn =
    [ SERVER ->
        let CHAN = accept SERVER in
        print "spawned a listener\n";
        let _ = par (spawn SERVER) (listener CHAN) in
            nop ]
     
def main =
    let SERVER = server 5000 5 in spawn SERVER


It works. Neat! I also wrote a small Sudoku solver and uncovered a small bug in Egel.