mo is an attempt to copy node.js's architecture based on guile and libuv.
mo(re) = guile + libuv.
mo is an attempt to copy node.js's architecture based on guile and libuv. On top of guile and libuv, have a fun to program in scheme in a platform like node.js. User will benefit from both scheme language features and asynchronous IO.
This project is incomplete and under heavy development.
(require-mo "http" 'http)
(http/start-server "0.0.0.0" 8080
(lambda (req resp)
(hashq-set! resp 'body "<b>hello world!</b>")
resp)
mo's module system is like node.js's. A mo file is a module. 'require-mo' is to load/evaluate file and 'export-mo' is to export functions in a module, so that other modules can access the functions.
(require-mo "module name" 'instance-name)
'require-mo' loads module if it's not loaded before. The second argument is the instance name. It's used as export function's prefix. The functions exported by module will be like 'instance-name/foo'.
(export-mo 'function)
'export-mo' exports the functions in current module.
example:
file: m1.mo
(define (foo)
(display "foo\n"))
(export-mo 'foo)
file: m2.mo
(require-mo "m1.mo" 'm)
(m/foo)
(next-tick callback):
'next-tick' registers a callback into event loop. When event loop is free from IO activities, callback will be invoked.
example:
(next-tick
(lambda ()
(display "hi\n")))
(set-timeout callback delay):
'set-timeout' registers a timer. After time indicated by delay is out, callback will be invoked.
example:
(set-timeout (lambda ()
(display "timeout\n"))
100)
(set-interval callback delay):
'set-interval' is like set-timeout, but the callback will be repeatly invoked after delay ms.
(clear-timer id)
set-timer/interval return a IP for timer reference. 'clear-timer' can be used to terminate the timer.
example:
(define timer (set-timeout
(lambda ()
(display "hi\n"))
1000))
(clear-timer timer)