[mercury-users] unsafe_set_char

Paul Bone pbone at csse.unimelb.edu.au
Sun May 30 16:35:51 AEST 2010


On Fri, May 28, 2010 at 03:00:33PM +0100, James Cussens wrote:
> Consider the following from the documentation for the string.m library  
> module:
>
>   % string.unsafe_set_char(Char, Index, String0, String):
>  ...
>   % This version is constant time, whereas string.set_char_det
>   % may be linear in the length of the string. Use with care!
>
> But I can't see how it can be constant time when it involves a call to  
> strcpy. I feel I must be missing something here. What's going on?
>
> More generally, being able to destructively update strings would be  
> useful, I think. I'm using Mercury to implemenent hidden Markov models  
> (which spit out strings) and currently make millions of calls to  
> string.unsafe_set_char, so if anyone has tips on quick (perhaps dirty)  
> methods of generating strings that would be appreciated. (My initial  
> experiments seem to show that using string is better than array(char), 
> btw.)
>

Hi James,

You're right, there is a bug here in the documentation.  I've filed it as bug
151.

I don't think we have a distructive update predicate for strings in the
standard library,

As for 'dirty' ways to acheive this, you could write your own foreign code that
uses distructive update.

Good luck.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 489 bytes
Desc: Digital signature
URL: <http://lists.mercurylang.org/archives/users/attachments/20100530/59fcafb1/attachment.sig>


More information about the users mailing list