[gambit-list] Termite in production?

James Long longster at gmail.com
Thu Dec 20 16:14:26 EST 2007


> I don't fully understand this. If you don't care about Termite
> portability (I'm not sure I do either) then wouldn't full integration
> with Gambit be the goal? Of so then why not finish up the remote ports
> bit?

Gambit's internal system uses macros to generate procedures quite a
bit.  This makes it sometimes tricky to wrap some of Gambit's
functionality with another interface.

Personally, I don't want any of Gambit's port procedures overridden.
Make a new library of remote port procedures.  I guess I don't see
Termite as much of a 'language' as an extension to Gambit.  It would
be annoying, for several different debugging / testing reasons, if I
couldn't access the real console or repl port.  It seems clearer to
have a level of code which works on abstract level and doesn't care
whether things are happening remotely or locally (in which case it
would always use the remote-* procedures), and also a lower level of
code which does care and can rely on Gambit being left as is.

Then you can just define a simple, clean remote-ports interface, and
not worry about wrapping every single gambit function.  Here's my
current remote ports library.  I also have a remote repl library which
can start a Gambit repl on any Termite node that has the remote ports
lib; if anyone wants it I can post it.

Great to hear that your working on it Guillaume!  It

;;;; Remote Ports
;;;;
;;;; TODO: Add support for bidirectional ports

(declare (block)
         (standard-bindings)
         (extended-bindings))

;; Remote Port Parameters
(define current-remote-error-port
  (make-parameter (spawn-output-port (current-error-port))))

(define current-remote-input-port
  (make-parameter (spawn-input-port (current-input-port))))

(define current-remote-output-port
  (make-parameter (spawn-output-port (current-output-port))))

;; Managing Remote Ports
(define (make-remote-input-port port)
  (spawn-input-port port))

(define (make-remote-output-port port)
  (spawn-output-port port))

(define (remote-output-port? obj)
  (termite-output-port? obj))

(define (remote-input-port? obj)
  (termite-input-port? obj))

(define (close-remote-input-port proc)
  (! (termite-input-port-pid proc)
     (lambda (p)
       (close-input-port p)
       (halt!))))

(define (close-remote-output-port proc)
  (! (termite-output-port-pid proc)
     (lambda (p)
       (close-output-port p)
       (halt!))))

;; Remote Input
(define (remote-read #!optional (proc (current-remote-input-port)))
  (!? (termite-input-port-pid proc) read))

(define (remote-read-char #!optional (proc (current-remote-input-port)))
  (!? (termite-input-port-pid proc) read-char))

(define (remote-read-line #!optional (proc (current-remote-input-port)))
  (!? (termite-input-port-pid proc) read-line))

(define (remote-peek-char #!optional (proc (current-remote-input-port)))
  (!? (termite-input-port-pid proc) peek-char))

(define (remote-char-ready? #!optional (proc (current-remote-input-port)))
  (!? (termite-input-port-pid proc) char-ready?))

;; Remote Output
(define (remote-write obj #!optional (proc (current-remote-output-port)))
  (! (termite-output-port-pid proc)
     (lambda (p) (write obj p))))

(define (remote-display obj #!optional (proc (current-remote-output-port)))
  (! (termite-output-port-pid proc)
     (lambda (p) (display obj p))))

(define (remote-write-char obj #!optional (proc (current-remote-output-port)))
  (! (termite-output-port-pid proc)
     (lambda (p) (write-char obj p))))

(define (remote-pretty-print obj #!optional (proc (current-remote-output-port)))
  (! (termite-output-port-pid proc)
     (lambda (p) (pretty-print obj p))))

(define remote-pp remote-pretty-print)

(define (remote-newline #!optional (proc (current-remote-output-port)))
  (! (termite-output-port-pid proc)
     (lambda (p) (newline p))))

(define (remote-force-output #!optional (proc (current-remote-output-port)))
  (! (termite-output-port-pid proc)
     (lambda (p) (force-output p))))

(define-macro (%%parse-output-args args)
  `(if (remote-output-port? (car rest))
       (values (car rest) (cdr rest))
       (values (current-remote-output-port) rest)))

(define (remote-write-all . rest)
  (receive (port objs) (%%parse-output-args rest)
    (for-each (lambda (obj) (remote-write obj port))
              objs)))

(define (remote-display-all . rest)
  (receive (port objs) (%%parse-output-args rest)
    (for-each (lambda (obj) (remote-display obj port))
              objs)))

(define (remote-pretty-print-all . rest)
  (receive (port objs) (%%parse-output-args rest)
    (for-each (lambda (obj) (remote-pretty-print obj port))
              objs)))

(define remote-pp-all remote-pretty-print-all)


-- 
James Long
Coptix, Inc.
longster at gmail.com



More information about the Gambit-list mailing list