Hi Olivier,

On Fri, Apr 11, 2025 at 9:50 AM Olivier Dion <olivier.d...@polymtl.ca> wrote:
>
> Like mentioned in the comment (look for the `(procedure? value)'
> clause), this does _not_ yield the same hash for a procedure if the
> module where this procedure came from is compiled.  And it's not
> possible to pass the procedure (a reference) to `compile' to get a
> compiled version.  I assume that the compiler would need lexical context
> for couple of its optimization anyway, so even if it did worked, we
> would not get the same bytecode.
>
> Note that hashing the source code won't work either because:
>
>   1. If not compiled, there is no source location available, thus not
>   usable in a REPL.
>
>   2. Hashing of the source does not make sense in my point of view.
>   Adding a newline to a function does not change its bytecode and should
>   yield the same hash.
>
> So I wonder if somebody has an idea on how to have reliable hash of
> procedure. That is, a given procedure will yield the same hash in
> different Guile processes, compiled or not.

Hashing by procedure content is not something you can do.  Procedures
are *opaque* objects.  As you've seen, the same procedure can be
represented in many different ways at runtime. What does it even mean
for two procedures to be the same, anyway?

Since procedures are opaque, the only hash that makes sense is hashq,
which hashes by object identity. If (eq? a b) is #t then the hash code
will be the same.

- Dave

Reply via email to