joshibharathiramana
2021-4-6 12:32:38

What is the idiomatic way to merge two dicts?


sorawee
2021-4-6 12:34:08

If they are both hash, you can use hash-union (or hash-union!)


sorawee
2021-4-6 12:35:43

if they are both assoc list, I think you can just append them, provided that there’s no common element in both assoc lists.


joshibharathiramana
2021-4-6 12:40:04

I came up with those myself, but wouldn’t those be leaky abstractions? Is there some way of doing it at the dict abstraction without exploiting the actual representation?


sorawee
2021-4-6 12:46:02

Yes for leaky abstractions, but unfortunately, dict-union(!) is not in the standard library. Feel free to submit a PR to add it.


joshibharathiramana
2021-4-6 12:47:24

Okay! So dict-union would have to check what the representation is and make the appropriate union, yes?


sorawee
2021-4-6 12:49:11

yep


sorawee
2021-4-6 12:49:58

well, there are several possible designs.


sorawee
2021-4-6 12:50:50

One could be, disallow the operation if all dicts are not implemented in the same way (e.g., (dict-union (hash 1 2) (list (cons 3 4))) is not allowed)


sorawee
2021-4-6 12:52:13

Another could be, if dicts are not implemented in the same way, the result will be implemented in the same way as the first argument. So:

(dict-union (hash 1 2) (list (cons 3 4))) would evaluate to (hash 1 2 3 4), but (dict-union (list (cons 3 4)) (hash 1 2)) would evaluate to '([1 . 2] [3 . 4])


hectometrocuadrado
2021-4-6 14:46:59

How can I load/store an image from/to a file?


hectometrocuadrado
2021-4-6 14:48:27

Also, I’m interested in being able to get the bytes of the image.


sorawee
2021-4-6 14:49:18

sorawee
2021-4-6 14:50:37

In particular, use read-bitmap to load from a file, and use the method save-file to store to a file.


hectometrocuadrado
2021-4-6 14:53:37

Nice, I guess there is one proc to get the data


hectometrocuadrado
2021-4-6 14:54:04

I need that to use it in the FFI


hectometrocuadrado
2021-4-6 14:57:53

Ive just seen the get-data-from-file method. I think it is what I need. Thanks!


jukkae
2021-4-6 22:43:56

@jukkae has joined the channel