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.

No comments:

Post a Comment