;;; Chicanery extras (export slurp) (define slurp (case-lambda (() (slurp (current-input-port))) ((port) (let loop ((ch (read-char port)) (acc '())) (if (eof-object? ch) (list->string (reverse acc)) (loop (read-char port) (cons ch acc))))))) (export with-output-to-string with-input-from-string) (define (with-output-to-string thunk) (call-with-port (open-output-string) (lambda (port) (parameterize ((current-output-port port)) (thunk)) (get-output-string port)))) (define (with-input-from-string s thunk) (call-with-port (open-input-string s) (lambda (port) (parameterize ((current-input-port port)) (thunk))))) (export displayed ->string written print) (define (displayed x) (with-output-to-string (lambda () (display x)))) (define ->string displayed) (define (written x) (with-output-to-string (lambda () (write x)))) (define (print . xs) (for-each display xs) (newline))