[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Guile ports

From: Zelphir Kaltstahl
Subject: Guile ports
Date: Mon, 28 Dec 2020 08:33:25 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0

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 <> writes:
>> Ludovic Courtès <> 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
>>   cd guile-zstd
>>   git checkout v0.1.1  # or f853c8eb81088f8fbf33d38e62cddea9a4984180
>>   git tag -v v0.1.1
>> Ludo’.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]