[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
A more generic REPL server
From: |
David Thompson |
Subject: |
A more generic REPL server |
Date: |
Fri, 04 Oct 2013 20:56:52 -0400 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:10.0.12) Gecko/20130116 Icedove/10.0.12 |
Hello all,
As some of you know, I am writing my own custom REPL that fits nicely
with my game framework, guile-2d. I just finished hacking (system repl
server) to suit my needs and things seem to be working well.
Looking upon the diff, I see that I only changed the serve-client
procedure. Thus, I think it would be a good idea to build some
abstraction that allows custom REPLs to be run, not just start-repl in
(system repl repl).
Here is the original serve-client method:
(define (serve-client client addr)
(with-continuation-barrier
(lambda ()
(with-input-from-port client
(lambda ()
(with-output-to-port client
(lambda ()
(with-error-to-port client
(lambda ()
(with-fluids ((*repl-stack* '()))
(start-repl))))))))))
(close-socket! client))
And here is my version:
(define (serve-client client addr)
(agenda-schedule
(colambda ()
(with-input-from-port client
(lambda ()
(with-output-to-port client
(lambda ()
(with-error-to-port client
(lambda ()
(with-fluids ((*repl-stack* '()))
(start-repl))))))))
(close-socket! client))))
In this snippet, start-repl comes from a guile-2d module, not (system
repl repl).
There's an abstraction lurking here, but I'm not quite sure what it is.
I've removed the continuation barrier, changed the start-repl procedure,
and wrapped everything in a form that creates a coroutine. I tried
simply adding an additional argument to spawn-server that specifies the
procedure used to serve the client. However, close-socket! is private,
and I don't think it would be a good idea to expose it.
Can anyone think of a good way to generalize this?
Thanks,
- Dave
- A more generic REPL server,
David Thompson <=