On 1-May-08, at 7:21 PM, Francisco wrote:
Oh thank you! And what about if want to do it on a network socket, I want to parse the input until a char is found, or until the end of the available input, but according to that input I need to respond using the same socket How do I do that?
You don't need to do anything special. The thread will block when the socket's buffer is empty (waiting for more data to come or the connection to be closed). You won't get a deadlock because the scheduler considers it is possible that the process at the other end of the connection will send more data later.
By the way, if you want to read text until a certain character you can use read-line and specify the character as the second parameter (it defaults to #\newline). Here are some examples:
(read-line (open-input-string "hello world\nhow are you?\n"))
"hello world"
(read-line (open-input-string "hello world\nhow are you?\n") #\space)
"hello"
(define (split str sep)
(read-all (open-input-string str) (lambda (p) (read-line p sep))))
(split "this is a sentence" #\space)
("this" "is" "a" "sentence")
Marc