[CM] How to iterate through a hash-table in C?

Iain Duncan iainduncanlists at gmail.com
Mon Dec 7 21:05:17 PST 2020


I think I found a decent solution, but am still curious if there is a
better that I am missing.  I can get C to do the equivalent of
(map values my-hashtable)
giving me a list of key value pairs.

So where h is an s7 pointer to a hash-table:

s7_pointer key_val_list = s7_call(s7, s7_name_to_value(s7, "map"),
s7_list(s7, 2, s7_name_to_value(s7, "values"), h));

I'm guessing that's as good as it gets, eh?
iain

On Mon, Dec 7, 2020 at 7:21 PM Iain Duncan <iainduncanlists at gmail.com>
wrote:

> Hi folks, I'm needing to iterate through the key value pairs of a
> hashtable from C code in order to make some functions that convert from Max
> dictionaries to S7 hashes and vice versa. I can't think of an elegant way
> to do this from C. The only thing I've thought of so far is that I could
> define a function to get the keys and call it from C..
>
> ie something like
>
> fun_get_keys = s7_eval_c_string(s7_scheme *sc, "(lambda (h)( map(
> lambda(p)(car p) h )");
>
> And then use C to call that function on my hashtable (which I have an s7
> pointer to). Is that a decent approach or am I missing something pretty
> obvious here?
>
> thanks
> iain
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cm-mail.stanford.edu/pipermail/cmdist/attachments/20201207/220e2cd0/attachment.html>


More information about the Cmdist mailing list