From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Zelphir Kaltstahl Newsgroups: gmane.lisp.guile.user Subject: Re: Question about an error with ports Date: Thu, 10 Mar 2022 22:32:04 +0000 Message-ID: References: <3f938fe1-9af4-9076-8d50-d1f7b2ddda36@posteo.de> <87ilslc0gn.fsf@laura> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="2301"; mail-complaints-to="usenet@ciao.gmane.io" To: Olivier Dion , guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Thu Mar 10 23:33:03 2022 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nSRLD-0000SD-3I for guile-user@m.gmane-mx.org; Thu, 10 Mar 2022 23:33:03 +0100 Original-Received: from localhost ([::1]:46854 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSRLB-0004Qe-Dg for guile-user@m.gmane-mx.org; Thu, 10 Mar 2022 17:33:01 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:46430) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSRKR-0004Am-7Z for guile-user@gnu.org; Thu, 10 Mar 2022 17:32:16 -0500 Original-Received: from mout01.posteo.de ([185.67.36.65]:38273) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSRKM-0003g5-Fg for guile-user@gnu.org; Thu, 10 Mar 2022 17:32:13 -0500 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 2B880240026 for ; Thu, 10 Mar 2022 23:32:05 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1646951526; bh=4jiW8cyt/NtgsKjT+Xq2hDwifOg9U1bedxvagFLbhf4=; h=Date:Subject:To:From:From; b=dDyDHklkRBId3EOzD1oQlOXSUcGdkTSwYiLw9lw1PkYqPOtj40mIBfifqG1dMHIBE dWEUqz5TCR3kKV1i69Bip+ILfNZkLL4zeKEQX3UKt/2peC0IG9w9/Oxw+6Xlflmxbp mv+8Y1PZXGxRyXRggiNzVTlz8bIpm43Pqy+Sf1riK+W08ydULMCmA/q2yL4EaXzADl 3LpfsD389TzwkxHGvf6ypdpDqOzLIDrmiGS60U+zYEWKW0BxR9EN3IckLaNHs1/Wlg qvDS1E5jVY9Zs8rLMjeJS9994ltQJwlP2Frkcdyd5GOV1CJZ6pRP38hBd+vt1hyXXq P98JHz+yhRvBQ== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4KF3hj0hDQz6tm5; Thu, 10 Mar 2022 23:32:04 +0100 (CET) Content-Language: en-US In-Reply-To: <87ilslc0gn.fsf@laura> Received-SPF: pass client-ip=185.67.36.65; envelope-from=zelphirkaltstahl@posteo.de; helo=mout01.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:18180 Archived-At: Hello Olivier! On 3/10/22 16:05, Olivier Dion wrote: > On Thu, 10 Mar 2022, Zelphir Kaltstahl 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