Email or username:

Password:

Forgot your password?
Top-level
Ramin Honary

@abcdw @otterz creating a very large linked-list like this would be very slow though, and the reverse->list function is an O(n) operation.

It might be better to write to a string port instead, and then return the string when (char-ready? port) returns #f.

2 comments
Andrew Tropin

@ramin_hal9001 @otterz Sounds very reasonable to me! Thank you for the idea, I guess I will use it in the implementation :)

Ramin Honary

@abcdw @otterz No problem!

(define (read-all-chars-as-string in-port)
  (let ((out-port (open-string-port)))
    (let loop ()
      (if (char-ready? in-port)
          (begin
            (write-char (read-char in-port) out-port)
            (loop))
          (get-output-string out-port)))))
Go Up