unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Zelphir Kaltstahl <zelphirkaltstahl@posteo.de>
To: guile-user@gnu.org
Subject: Guile ports
Date: Mon, 28 Dec 2020 08:33:25 +0100	[thread overview]
Message-ID: <58e8f409-2a26-2384-2b2d-79bc0a622a27@posteo.de> (raw)
In-Reply-To: <8735zqfmte.fsf@web.de>

On that note, I would like to mention, how elegant I find Guile's port
system. You know, the whole "write to port to write to a file", "write
to a string port" (for example when you want to avoid building many
temporary in-between strings), "reading from ports", etc..

I've not seen something like this in other languages yet. Not sure how
much of it is Scheme standards, but I like it. It composes quite well,
at least on the surface, when you write procedures. You can always
accept an optional or keyword argument, which is the port and then leave
the choice of what that port is to the caller. It seems more elegant
than a file handle or a location of a file or something like that in
some other programming languages, where I wanted something similar.

At the beginning it was a little confusing to me, as I had not the
understanding of what a port is in Guile (and perhaps my understanding
is still superficial, but at least working), but now I enjoy it.

On 12/28/20 7:48 AM, Dr. Arne Babenhauserheide wrote:
> Hi Ludo,
>
> that’s pretty cool! Thank you!
>
> Looking at the readme I get the feeling that two little helpers could be
> useful:
>
>    (call-with-zstd-output-file "compressed.zstd"
> 	(lambda (port)
> 	  (define data
> 	    ;; Read the input file in memory.
> 	    (call-with-input-file "input-file.txt"
> 	      get-bytevector-all))
>
> 	  ;; Write data to PORT.
> 	  (put-bytevector port data)))
>
>   (call-with-zstd-input-file "compressed.zst"
> 	(lambda (port)
> 	  ;; Read decompressed data from PORT.
> 	  ...))
>
> Potentially with streaming added (if that’s possible from the library):
>
>    (call-with-zstd-output-file "compressed.zstd"
> 	(lambda (outport)
>       (call-with-input-file "input-file.txt"
> 	    (lambda (inport)
>           (let loop ((data (get-bytevector-some inport)))
>             (when (not (eof-object? data))
>               (put-bytevector outport data)
>               (loop (get-bytevector-some inport))))))))
>
> Also maybe a minimal representation of the commandline-interface:
>
>    (zstd-compress "input-file.txt" #:output "compressed.zst")
>    (zstd-decompress "compressed.zstd" #:output "cleartext-file.zst")
>
> Best wishes,
> Arne
>
> Ludovic Courtès <ludo@gnu.org> writes:
>
>> Ludovic Courtès <ludo@gnu.org> skribis:
>>
>>> I’m pleased to announce the first release of Guile-zstd:
>> Oops, a file was missing from the repo, so here’s a brand new release!
>>
>>   git clone https://notabug.org/guile-zstd/guile-zstd
>>   cd guile-zstd
>>   git checkout v0.1.1  # or f853c8eb81088f8fbf33d38e62cddea9a4984180
>>   git tag -v v0.1.1
>>
>> Ludo’.
>
-- 
repositories: https://notabug.org/ZelphirKaltstahl




  reply	other threads:[~2020-12-28  7:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-27 14:01 Guile-zstd 0.1.0 released Ludovic Courtès
2020-12-27 15:00 ` Guile-zstd 0.1.1 released Ludovic Courtès
2020-12-28  6:48   ` Dr. Arne Babenhauserheide
2020-12-28  7:33     ` Zelphir Kaltstahl [this message]
2021-01-04 17:21     ` Ludovic Courtès
2021-01-04 19:19   ` Aleix Conchillo Flaqué

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=58e8f409-2a26-2384-2b2d-79bc0a622a27@posteo.de \
    --to=zelphirkaltstahl@posteo.de \
    --cc=guile-user@gnu.org \
    /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).