Always better with an example: > (with-input-from-string (with-output-to-string (λ() (write 'x) (write 'y))) (λ() (list (read) (read) (read)))) '(xy #<eof> #<eof>) > (with-input-from-string (with-output-to-string (λ() (write 'x) (write " ") (write 'y))) (λ() (list (read) (read) (read)))) '(x " " y) > (with-input-from-string (with-output-to-string (λ() (write 'x) (display " ") (write 'y))) (λ() (list (read) (read) (read)))) '(x y #<eof>)
Laurent On Mon, Nov 5, 2012 at 9:41 AM, Laurent <laurent.ors...@gmail.com> wrote: > > > > On Fri, Nov 2, 2012 at 7:48 PM, Laurent <laurent.ors...@gmail.com> wrote: > >> >> >> You're using just `write', so you need some whitespace between items: >>> >>> > (with-input-from-string >>> (with-output-to-string (λ() (write 'x) (write 'y))) >>> read) >>> 'xy >>> >> >> > >> >> Wow, thanks a lot, I would have never thought about that. I thought that >> 'write' was sending data, not mere characters. >> Writing a space after each output indeed solves the problem. >> > > For reference, one needs to use (printf " ") or (display " ") but not > (write " ") or (print " "), because, IIUC, 'write' does send data, but does > not add delimiters to the data if there are none yet. > I.e., a string like " " is self-delimited, a list (a b c) is also > self-delimited, but symbols and numbers are not. This means that the > delimiter must be added by hand. > 'display' sends a space to the stream, whereas 'write' sends a > self-delimited data string " ". > > Laurent > >
____________________ Racket Users list: http://lists.racket-lang.org/users