[mercury-users] Converting time_t to int using common library?

Julien Fischer juliensf at csse.unimelb.edu.au
Tue Feb 13 20:55:11 AEDT 2007


On Tue, 13 Feb 2007, Julian Fondren wrote:

> On 2/13/07, doug.auclair at logicaltypes.com <doug.auclair at logicaltypes.com> 
> wrote:
>> So, is there an elegant way to convert time_t to int
>> using the supplied modules in the library that I'm
>> missing?  If not, could module random be modified
>> to allow a seed to initialize the supply to be a time_t
>> as well as an int?
>
> As an alternate solution, attached is a a patch that
> adds to library/random.m ; see docs, below.
>
> Cheers,
> Julian
>
>
>       % random.init(RS, !IO): creates a supply of random numbers RS
>       % using a sensible default seed (e.g., on POSIX it will use
>       % the number of seconds since the unix epoch.)
>       %
> :- pred random.init(random.supply::uo, io::di, io::uo) is det.
>
>       % random.init(RS): creates a supply of random numbers RS
>       % using a sensible default seed (e.g., on POSIX it will use
>       % the number of seconds since the unix epoch.)  This function
>       % differs from the previous predicate in that it only determines
>       % the 'sensible default seed' when first evaluated, and
>       % thereafter uses that same seed.
>       %

That latter part does't seem to be a particularly useful behaviour to me.

> :- func random.init = (random.supply::uo) is det.

BTW, you should avoid using the old foreign language interface (as you did 
in the attached patch) in favour of the new one, e.g.

   pragma foreign_proc("C", ...	instead of pragma c_code
   pragma foreign_decl("C", ...  instead of pragma c_header_code

The old interface is deprecated and we will be removing support for it
at some point.  (Also the implementation of pragma c_code is a bit
unpredictable w.r.t to the purity system.)

Julien.

--------------------------------------------------------------------------
mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the users mailing list