unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Zelphir Kaltstahl <zelphirkaltstahl@posteo.de>
To: Olivier Dion <olivier.dion@polymtl.ca>, guile-user@gnu.org
Subject: Re: Question about an error with ports
Date: Thu, 10 Mar 2022 22:32:04 +0000	[thread overview]
Message-ID: <b50462bf-fc45-3c16-fd1f-c5b314ce4213@posteo.de> (raw)
In-Reply-To: <87ilslc0gn.fsf@laura>

Hello Olivier!

On 3/10/22 16:05, Olivier Dion wrote:
> On Thu, 10 Mar 2022, Zelphir Kaltstahl <zelphirkaltstahl@posteo.de> wrote:
>
>> I have the following questions:
>>
>> (1) Is the read-from-write-to procedure useful at all, or is there a better way
>> to get all stuff from an input port and output it to an output port, avoiding
>> possibly large string values?
> On Linux, there's slice(2) for pipes that does exactly that.
>
> Otherwise, I think this version is a better fit
>
> (define splice
>    (lambda (in-port out-port)
>      "Read from an IN-PORT and write to OUT-PORT"
>      (let loop ([bv (get-bytevector-some in-port)])
>        (unless (eof-object? bv)
>          (put-bytevector out-port bv)
>          (loop (get-bytevector-some in-port))))))
>
> you should not close OUT-PORT.  This break the REPL in my case if using
> the `current-output-port`.
>
Thanks! That solves the problem. I guess a caller of the function can decide 
themselves, when they want to close the port, so no need to close it inside that 
procedure. Closing it inside the procedure would also only limit its use, 
because it could only be used with ports, which are OK to close.

When not closing the port, using (unless ...) also makes more sense than what I had.

Just one question: Why is get-bytevector-some better than get-bytevector-n and 
specifying a number of bytes?

Best regards,
Zelphir

-- 
repositories: https://notabug.org/ZelphirKaltstahl




  reply	other threads:[~2022-03-10 22:32 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-10  1:26 Question about an error with ports Zelphir Kaltstahl
2022-03-10 15:05 ` Olivier Dion via General Guile related discussions
2022-03-10 22:32   ` Zelphir Kaltstahl [this message]
2022-03-10 23:46     ` Olivier Dion via General Guile related discussions
2022-03-11 12:05       ` Chris Vine
2022-03-11 14:58         ` Olivier Dion via General Guile related discussions
2022-03-11 17:26           ` Chris Vine
2022-03-11 17:47             ` Olivier Dion via General Guile related discussions
2022-03-11 18:13             ` Chris Vine
2022-03-11 19:48               ` Maxime Devos
2022-03-11 19:49               ` Maxime Devos
2022-03-12  0:10                 ` Chris Vine
2022-03-12  0:27                   ` Chris Vine
2022-03-11 12:11       ` Maxime Devos
2022-03-11 15:06         ` Olivier Dion via General Guile related discussions

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b50462bf-fc45-3c16-fd1f-c5b314ce4213@posteo.de \
    --to=zelphirkaltstahl@posteo.de \
    --cc=guile-user@gnu.org \
    --cc=olivier.dion@polymtl.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).