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: Andy Bennett
Subject: Re: [Chicken-users] Variable Capture in message-digest
Date: Tue, 26 Apr 2016 09:26:55 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Icedove/38.7.0

Hi,

>> 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").

Thanks Peter!

That is rather confusing: I thought each module imported its own
identifiers and had its own namespace.

As string->blob is part of "library" I'm not importing it from anywhere
so how would I "except" it?




Regards,
@ndy

-- 
address@hidden
http://www.ashurst.eu.org/
0290 DA75 E982 7D99 A51F  E46A 387A 7695 7EBA 75FF


Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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