Thinking until the 2147483648'th second

About This

I think all of the files I linked to in some of my older posts are gone now. I am working on fixing them.

Monday, July 16, 2007

Gambit-C Erlang FFI

I have finished up a prototype Gambit-C Erlang FFI that I have been working on. It's a neat technique and could be very valid in a situation where you want to use Scheme for various tasks in an environment like Yaws. However, if using Scheme for more than achieving various tasks, and using it for some of its mind-blowingly weird and cool stuff and basing an application around this, you're better off using Termite.

If you're interested, you can download it.

To be able to take advantage of all of Erlang's distributing
mechanisms, we need to use a proxy Erlang process and communicate through ports, as described here:

This is what my FFI is based on. It's a very basic implementation, but it allows to write a Scheme app like this:

(load "erlang")

(define (bar num)
(+ num 2))

(define (foo num)
(* num 2))

(define (start)
(let loop ((term (erl-receive)))
(if (not (eqv? term 'close))
(let* ((fun (car term))
(args (cdr term))
(res (apply (eval fun) args)))
(erl-send (erl-element res))
(loop (erl-receive)))))))

And then in Erlang do this:
 2> test:start("./test_process").
3> test:call({foo,10}).
4> test:call({foo,12}).
5> test:call({foo,25.2}).
6> test:call({foo,12.25}).
7> test:call({bar,100}).
8> test:call({bar,100.123}).
Pretty neat.

Random Notes

I work at Coptix

Ideas / To-do

  • Research .Mac style photo gallery for screenshots