Skip to content

Instantly share code, notes, and snippets.

@danking
Created December 14, 2010 06:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danking/740084 to your computer and use it in GitHub Desktop.
Save danking/740084 to your computer and use it in GitHub Desktop.
weird read-line halting
#lang racket
(require rackunit
"main.rkt")
(provide tea-eval auto-cleanup-process)
;; tea-eval : SExp -> (list String String)
;; the first string is (hopefully) the output
;; the second string is the full output of the command, check this if the first
;; doesn't make any sense
(define (tea-eval sexp)
(auto-cleanup-process
(lambda (p out in err)
(write-string (string-append
;; BROKEN: should refernece local file's
;; directory
(file->string "environment.js") ;; bunch of JavaScript code
"\nEnvironmentModule(this);\n\n"
(tea->js sexp)) ;; '(+ 1 2) => "a0(1, 2);\n" and '(define x 3) => "var x = 3;\n"
in)
(flush-output in) ;; otherwise it seems to hang before this line
(read-line err) ;; skip the Rhino header
(read-line err))
"/usr/bin/env"
"rhino"))
(define-syntax auto-cleanup-process
(syntax-rules ()
[(_ procedure command args ...)
(begin
(let-values ([(a-subprocess stdout stdin stderr)
(subprocess #f #f #f command args ...)])
(let ([value (procedure a-subprocess stdout stdin stderr)])
(subprocess-kill a-subprocess #t)
(close-input-port stdout)
(close-input-port stderr)
(close-output-port stdin)
value)))]))
;; Below is a REPL session.
> (require "eval.rkt")
> (tea-eval '(+ 1 2))
"js> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > js> js> js> js> 3"
> (tea-eval '(define x 3))
@danking
Copy link
Author

danking commented Dec 14, 2010

danking@danking-desktop:~ 22:48 $ rhino
Rhino 1.7 release 2 2010 09 15
js> var x = 3;
js>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment