From 93b2ab23b1b0849a6d822403944d1ddc25e04921 Mon Sep 17 00:00:00 2001 From: interp Date: Sat, 14 Sep 2002 15:18:12 +0000 Subject: [PATCH] remove external state error --- web-server/root/surflets/news.scm | 57 ++++++++++++++++++------------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/web-server/root/surflets/news.scm b/web-server/root/surflets/news.scm index 20b64b6..2c3b946 100644 --- a/web-server/root/surflets/news.scm +++ b/web-server/root/surflets/news.scm @@ -5,12 +5,36 @@ httpd-responses crlf-io) (begin - (define (main req) + (define *data* '()) + + (define (read-data) (let ((news-input (open-input-file "news.txt"))) - (let loop () - (let ((next-line (read-crlf-line news-input))) - (if (eof-object? next-line) - (send/finish + (let loop ((next-line (read-crlf-line news-input))) + (if (eof-object? next-line) + (close news-input) + (begin + (set! *data* (cons next-line *data*)) + (loop (read-crlf-line news-input))))))) + + (define (main req) + (if (null? *data*) (read-data)) + (let loop ((count (- (length *data*) 1))) + (if (< count 0) + (send/finish + (make-response + http-status/ok + (status-code->text http-status/ok) + (time) + "text/html" + '() + (make-writer-body + (lambda (out options) + (format out + "

THAT'S IT

+That's it..."))))) + (begin + (send/suspend + (lambda (next-url) (make-response http-status/ok (status-code->text http-status/ok) @@ -20,23 +44,10 @@ (make-writer-body (lambda (out options) (format out - "

THAT'S IT

-That's it..."))))) - (begin - (send/suspend - (lambda (next-url) - (make-response - http-status/ok - (status-code->text http-status/ok) - (time) - "text/html" - '() - (make-writer-body - (lambda (out options) - (format out - "

~a

+ "

~a

read more..." - next-line - next-url)))))) - (loop))))))) + (list-ref *data* count) + next-url)))))) + (loop (- count 1)))))) )) +