[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to include a file/definition temporarily?
From: |
David Kastrup |
Subject: |
Re: How to include a file/definition temporarily? |
Date: |
Mon, 20 Sep 2010 21:17:23 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) |
Carl Sorensen <address@hidden> writes:
> On 9/20/10 3:54 AM, "David Kastrup" <address@hidden> wrote:
>
>> Carl Sorensen <address@hidden> 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