unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: "Philip McGrath" <philip@philipmcgrath.com>
To: guile-devel@gnu.org
Subject: Re: Functional datatypes in Guile
Date: Tue, 28 Feb 2023 11:54:48 -0500	[thread overview]
Message-ID: <ae488abd-267f-47a2-ad75-8727bfd1e225@app.fastmail.com> (raw)
In-Reply-To: <CAJ=RwfYdTLdKyEu2embKFa_ixwZ--rpQsHYjaM-=Q2vKq9oOmg@mail.gmail.com>

Hi,

On Tue, Feb 28, 2023, at 11:04 AM, Thompson, David wrote:
> Hi pukkamustard,
>
> On Tue, Feb 28, 2023 at 3:34 AM pukkamustard <pukkamustard@posteo.net> wrote:
>>
>>
>> I've been using SRFI-146
>> (https://srfi.schemers.org/srfi-146/srfi-146.html) for functional
>> mappings. There's a Guile port:
>> https://inqlab.net/git/guile-srfi-146.git/ (also in Guix -
>> guile-srfi-146).
>
> Your Guile port of (srfi srfi-146 hash) looks really nice!  A
> functional hash is the most important data structure for our needs at
> Spritely. Do you know if it's thread-safe (unlike vhashes)?

Another issue with vhashes is that vhash-cons works like cons with an alist: if the vhash already had an entry for the given key, the returned vhash will retain a reference to both the new value and the old value, potentially preventing the old value from being garbage-collected.

>  Andy's
> fash implementation uses atomic boxes, for example.
>

I have a work-in-progress port of the three immutable hash-table implementations from Racket CS. The two portable backends, Patricia tries and vector-based hash array mapped tries, offer a time-space tradeoff. There's commentary in  https://github.com/racket/racket/blob/master/racket/src/cs/rumble/intmap.ss

The backend actually used now by Racket CS is a variant of the HAMT implementation backed by a new primitive type, "stencil vectors", a kind of sparse array. They need a little cooperation from the runtime system, but they're designed to distill the essence of what functional data structure implementations need from the runtime and GC into a minimal primitive type. There's a paper with details and more benchmarks: it reports that Racket's stencil-vector HAMTs "perform in the same neighborhood as" Clojure's PersistentHashMap and Java's CHAMP. <https://www-old.cs.utah.edu/plt/publications/dls21-tzf.pdf>

There's Racket documentation for stencil vectors at <https://docs.racket-lang.org/reference/stencil_vectors.html> or the Guix package "racket", and the corresponding Chez Scheme documentation is in the Guix package "chez-scheme-for-racket:doc".

Even the non–stencil-vector backends should be serviceable, though!

-Philip



  reply	other threads:[~2023-02-28 16:54 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-27 13:17 Functional datatypes in Guile Jessica Tallon
2023-02-28  7:47 ` Maxime Devos
2023-02-28  8:22 ` pukkamustard
2023-02-28 16:04   ` Thompson, David
2023-02-28 16:54     ` Philip McGrath [this message]
2023-03-04 16:38     ` pukkamustard
2023-03-05 12:58       ` Linus Björnstam
2023-03-07 15:02         ` pukkamustard
2023-06-10 16:47   ` Ludovic Courtès
2023-06-10 18:28     ` Dr. Arne Babenhauserheide
2023-06-16  5:15     ` pukkamustard
2023-06-21 21:53       ` Ludovic Courtès
2023-02-28 17:03 ` Clojure support Lassi Kortela
2023-03-04 10:28   ` Linus Björnstam
2023-03-04 11:22     ` Philip McGrath
2023-05-07 15:36       ` Linus Björnstam
2023-05-13 22:10   ` Rob Browning
2023-05-20  9:36     ` Maxime Devos
2023-05-21  2:29       ` Rob Browning

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=ae488abd-267f-47a2-ad75-8727bfd1e225@app.fastmail.com \
    --to=philip@philipmcgrath.com \
    --cc=guile-devel@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).