guix-devel
[Top][All Lists]
Advanced

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

Re: Merging guix.el


From: Ludovic Courtès
Subject: Re: Merging guix.el
Date: Wed, 03 Sep 2014 09:09:07 +0200
User-agent: Gnus/5.130011 (Ma Gnus v0.11) Emacs/24.3 (gnu/linux)

Alex Kost <address@hidden> skribis:

> Ludovic Courtès (2014-09-01 16:10 +0400) wrote:

[...]

>> Would ‘vlist-fold’ work?
>>
>> scheme@(guile-user)> (vhash-cons 'a 1 (vhash-cons 'b 2 (vhash-cons 'a 3 
>> vlist-null)))
>> $2 = #<vhash 26fd3a0 3 pairs>
>> scheme@(guile-user)> (vlist-fold cons '() $2)
>> $3 = ((a . 3) (b . 2) (a . 1))
>
> Sorry, I don't see how it could work.  Here is an example:
>
> ;; What I currently have is a hash-table like this one:
> (define table (make-hash-table 3))
>
> (hash-set! table 'a '(1 2 3))
> (hash-set! table 'b '(4))
> (hash-set! table 'c '(5 6))
>
> ;; And I can easily fold through unique keys like this:
> (hash-fold (lambda (key entries res)
>              (cons (cons key (apply + entries)) res))
>            '()
>            table) ; => ((c . 11) (b . 4) (a . 6))
>
> ;; What you suggest is a vhash like this:
> (define vhash
>   (vhash-cons
>    'a 1
>    (vhash-cons
>     'a 2
>     (vhash-cons
>      'a 3
>      (vhash-cons
>       'b 4
>       (vhash-cons
>        'c 5
>        (vhash-cons
>         'c 6 vlist-null)))))))
>
> ;; But how can I fold through unique keys there?

With a vhash, you can’t really do that efficiently.  ‘vlist-fold’ allows
you to iterate over the list of key/value pairs, but in the order in
which they appear (so you don’t get all the 'a, and then all the 'b.)

If that’s not sufficient, then yes, hash tables may be best.

>> When we merge, would you like to rewrite history and make the whole
>> thing appear as a single “perfect” commit, or just merge ‘emacs-ui’ into
>> ‘master’?  (I often do the former, but I’m fine with the latter here.)
>
> I don't have a preference here.  I can do a single commit if it is more
> appropriate.  Would the following commit message be OK?

Yes, that would be perfect.

Feel free to proceed whenever is convenient for you.

Thanks!

Ludo’.



reply via email to

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