[racket] flush is not enough, a list is needed

From: Laurent (laurent.orseau at gmail.com)
Date: Mon Nov 5 03:51:16 EST 2012

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.orseau at gmail.com> wrote:

>
>
>
> On Fri, Nov 2, 2012 at 7:48 PM, Laurent <laurent.orseau at 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20121105/f4563d44/attachment.html>

Posted on the users mailing list.