poke-devel
[Top][All Lists]
Advanced

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

Re: [RFC] `time' builtin


From: Mohammad-Reza Nabipoor
Subject: Re: [RFC] `time' builtin
Date: Mon, 9 Nov 2020 00:08:42 +0330

Hi, Jose!

On Sun, Nov 08, 2020 at 09:12:04PM +0100, Jose E. Marchesi wrote:
> 
> Hi people!
> 
> So we need a `time' builtin function to get the time :)
> 
> The main motivation is to build seeds for the already existing `rand':
> 
>   fun rand = (uint<32> seed = 0) int<32>:
> 
> Now the question is: what would be a good prototype for `time'?  What
> should it return?  We could:
> 
> a) Make it return seconds since the Epoch, or
> b) something more elaborated and precise like a struct tm.
> 
> Note that we already have a `ptime' function in the standard library
> that gives a date in seconds since the Epoch prints a human-readable
> version of it:
> 
>   fun ptime = (uint<64> seconds) void:
> 
> So maybe a) is more than enough... thoughts?
> 

I think `struct timespec` is a better option, because
  1) it only has two fields (one for seconds and one for nanoseconds)
  2) Using the nanoseconds part is also useful for seeding the `rand`.
     (Disclaimer: I'm not an expert in pseudo-random number generators)


```poke
type timespec = struct
  {
    uint<64> sec;
    uint<64> nsec;
  };
```

TBH I really hate the `tv_` prefix in `struct timespec`.


Regards,
Mohammad-Reza


Reference: https://en.cppreference.com/w/c/chrono/timespec


reply via email to

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