Carl Sorensen <[email protected]> writes:
> On 9/20/10 3:54 AM, "David Kastrup" <[email protected]> wrote:
>
>> Carl Sorensen <[email protected]> writes:
>>
>>> This is a good thought as a temporary workaround. However, it won't work
>>> as-is, because fretboard-table is a hash table. We'd need to define a
>>> hash-table copy function:
>>>
>>> (define (hash-table-copy my-table)
>>> (let ((new-hash-table (make-hash-table 100)))
>>> (hash-for-each (lambda (key value)
>>> (hash-set! new-hash-table key value))
>>> my-table)
>>> new-hash-table))
>> (hash-fold
>> (lambda (key value tab)
>> (hash-set! tab key value))
>> (make-hash-table 101)
>> my-table))
>>
>> Does not require a closure. And the size argument is recommended to be
>> prime. Which 100 is not exactly.
>
> Thanks. I looked at hash-fold, and thought about how it could work,
> but the description in the Guile docs (which was a bit cryptic) didn't
> help me find this solution.
To make it a solution, it is missing the return value from the fold
function. Sigh. So make that
(hash-fold
(lambda (key value tab)
(hash-set! tab key value)
tab)
(make-hash-table 101)
my-table))
Presumably hash-for-each is implemented via hash-fold (as the latter is
the only mentioned in the guile documentation), so this version is
conceivably faster. More importantly, one can find it in the guile
documentation.
--
David Kastrup
_______________________________________________
lilypond-user mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/lilypond-user