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:
http://www.erlang.org/doc/tutorial/erl_interface.html#5
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")And then in Erlang do this:
(define (bar num)
(+ num 2))
(define (foo num)
(* num 2))
(define (start)
(start-erl)
(let loop ((term (erl-receive)))
(if (not (eqv? term 'close))
(begin
(let* ((fun (car term))
(args (cdr term))
(res (apply (eval fun) args)))
(erl-send (erl-element res))
(loop (erl-receive)))))))
(start)
2> test:start("./test_process").Pretty neat.
<0.38.0>
3> test:call({foo,10}).
20
4> test:call({foo,12}).
24
5> test:call({foo,25.2}).
50.4000
6> test:call({foo,12.25}).
24.5000
7> test:call({bar,100}).
102
8> test:call({bar,100.123}).
102.123
9>
1 comment:
if using Scheme for more than achieving various tasks, and using it for some of its mind-blowingly weird
Post a Comment