[chuck-users] easy random numbers
Scott Wheeler
wheeler at kde.org
Wed Nov 21 05:36:11 EST 2007
Scott Wheeler wrote:
> Here are a couple examples of date / time APIs:
>
> http://doc.trolltech.com/4.3/time.html
> http://www.boost.org/doc/html/date_time.html
>
After looking at the Java API for dates and times I found that it
delegates things in a way that I found nice.
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Date.html
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Calendar.html
It has separation between a Date, which is basically a unix-epoch
timestamp and a calendar class which manages all conversions done on
that date (and a separate formatting class for reading and wring
dates). Mostly just to see how much work it actually is to extend
ChucK's type system I wrote something similar to the Date class, called
Timestamp (Time is already taken).
The API is:
Timestamp
- int secondsSinceEpoch()
- void setSecondsSinceEpoch(int seconds)
+ Timestamp current() [static]
So, a simple example:
<<< Timestamp.current().secondsSinceEpoch() >>>;
1::second => now;
Timestamp t;
t.setSecondsSinceEpoch(1);
<<< t.secondsSinceEpoch() >>>;
Timestamp.current() @=> t;
<<< t.secondsSinceEpoch() >>>;
Produces:
1195641120 :(int)
1 :(int)
1195641121 :(int)
Random other notes:
- The CVS server isn't responding at the moment. It connects, but diffs
don't work, so this is based on the last release.
- ChucK's type system is scattered across quite a few places. On the
wishlist-of-things-nobody'll-every-have-time-for would be consolidating
(and cleaning it up) a bit. Possibly en route to a 64-bit port since a
lot of the type system relies on casts from integers to pointers.
(Sidenote there -- would simply using a long long for the t_CKUINT
potentially work on 64-bit platforms? May try that later...)
- I tried to follow the current coding style despite difference in taste
(or some things that are generally not great C++ practice) so that the
code would fit with the rest if the authors want to check it in.
- This may not work on Windows. Should work on Mac and Linux. There's
a universal binary (Mac) here:
http://developer.kde.org/~wheeler/files/chuck.gz
-Scott
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: chuck-timestamp.diff
Url: http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20071121/e1b59dcd/attachment.bat
More information about the chuck-users
mailing list