#lang racket/base (require net/sendurl racket/list web-server/servlet web-server/servlet-env "package.rkt") ;; A hacky way to test the evaluation. ;; Channel's meant to serialize use of the web server. (define ch (make-channel)) ;; start up the web server ;; The web server responds to two types of requests ;; ?p Inputting a program ;; ?r Getting a response (void (thread (lambda () (define (start req) (cond [(exists-binding? 'p (request-bindings req)) ;; Create a web page whose content contains ;; the script. (let ([program (channel-get ch)] [op (open-output-bytes)]) (fprintf op #<

Running program.

EOF ) (response/full 200 #"Okay" (current-seconds) TEXT/HTML-MIME-TYPE empty (list #"" (get-output-bytes op))))] [(exists-binding? 'r (request-bindings req)) (channel-put ch (extract-binding/single 'r (request-bindings req))) `(html (body (p "ok")))] [else `(html (body (p "Loaded")))])) (serve/servlet start #:banner? #f #:launch-browser? #f #:quit? #f #:port 8080 #:servlet-path "/eval")))) ;; A little driver to test the evalution of expressions, using a browser to help. (define (evaluate e) ;; Send the program to the web browser, and wait for the thread to send back (send-url "http://localhost:8080/eval?p=t" #f) (channel-put ch e) (channel-get ch))