chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Variable Capture in message-digest


From: Peter Bex
Subject: Re: [Chicken-users] Variable Capture in message-digest
Date: Mon, 25 Apr 2016 19:54:42 +0200
User-agent: Mutt/1.5.23 (2014-03-12)

On Mon, Apr 25, 2016 at 05:55:35PM +0100, Andy Bennett wrote:
> Here is my minimal test case:
> 
> -----
> (use message-digest sha2)
> 
> (define (string->blob string)
>  (abort "no way"))
> 
> (define digest (initialize-message-digest (sha256-primitive)))
> 
> (assert (message-digest? digest))
> 
> (message-digest-update-object  digest "x")
> (pp (finalize-message-digest digest 'blob))
> -----
> 
> This aborts with "no way" during the call to message-digest-update-object.
> 
> 
> message-digest is expecting to get string->blob from the library
> (http://api.call-cc.org/doc/library/string-%3Eblob ) but I'm reusing
> that name in my program for something else.
> 
> Even tho' I define my string->blob after I (use message-digest), it
> seems to affect the binding in the message-digest code.
> 
> Is this expected behaviour?

Yes, in some cases we even do this intentionally: this is basically
performing a set! on an imported identifier, nothing special.

To avoid this, simply rename, prefix or omit ("except") the string->blob
identifier as you import it.  The compiler should give you a warning when
you do this, but it only does that when the code is in a module.  Try
compiling the above program with -M, you'll see the warning (and an error
about not importing "extras" to get "pp").

Cheers,
Peter

Attachment: signature.asc
Description: Digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]