; Take cars while p; return (took rest) (define (take-while p s) (if (null s) ;then (list 'nil 'nil) ;else (if (p (car s)) ;then (let next (take-while p (cdr s)) next-took (first next) next-rest (second next) (list (cons (car s) next-took) next-rest)) ;else (list 'nil s)))) ; car of list-string s is printable char (define (is-printable c) (str-le '! c)) ; car of list-string s is white space (define (is-white c) (str-lt c '!)) ; car of list-string s is newline (define (is-nl c) (eq nl c)) (assert-equal '((f i r s t) (" " w o r d)) (take-while is-printable (explode '"first word"))) (assert-equal (mapcar '(" " "foo bar ") explode) (take-while is-white (explode '" foo bar "))) (assert-equal (mapcar '("\ " "one two") explode) (take-while is-nl (explode '" one two"))) (define (split p s) (if (null s) 'nil (let _ (say (list 'CALL_split (cdr s))) w:ws (split p (cdr s)) _ (say (list '>>>>>>>>>> w:ws)) (if (null w:ws) (if (p (car s)) (list 'nil) (list (list (car s)))) (let w (car w:ws) ws (cdr w:ws) (if (p (car s)) (if (null w) (cons 'nil ws) ; join nils here (cons 'nil w:ws)) (if (null w) (cons (list (car s)) ws) (cons (cons (car s) w) ws)) )))))) (define (split-eq c s) (split (lambda (x) (eq x c)) s)) (define (split-nl s) (split-eq nl s)) (define (split-white s) (split is-white s)) (assert-equal (mapcar '(one two) explode) (split-white (explode '"one two"))) (assert-equal (mapcar '(one two) explode) (split-white (explode '"one two"))) (assert-equal '(nil (o n e) (t w o)) (split-white (explode '" one two"))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define Header200 "HTTP/1.0 200 OK Connection: close Content-Type: text/html; charset=iso-8859-1 ") (define (html-escape s) (define (Title s) (implode "" (html-escape s) ""))) (let input (readline) (def 'output (implode (append (explode (quote "HTTP/1.0 200 OK Connection: close Content-Type: text/html; charset=iso-8859-1 FOO foo bar baz
" )) input ) )) ) )