Created
December 14, 2010 06:47
-
-
Save danking/740084 to your computer and use it in GitHub Desktop.
weird read-line halting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
danking@danking-desktop:~ 22:48 $ rhino
Rhino 1.7 release 2 2010 09 15
js> var x = 3;
js>