[chuck-users] cast dur to time?

mike clemow gelfmuse at gmail.com
Mon Jan 7 14:27:30 EST 2008


On Jan 7, 2008 1:50 PM, Kassen <signal.automatique at gmail.com> wrote:

> <snip>
> <<<now /minute>>>; is quite legal and will return a float expressing the
> amount of minutes the VM has been alive. I see "now" and other times as a
> duration with the start of the VM as it's start.
>
> So; we can divide "now" by a duration and get a float but a float times a
> duration will always be a "duration" and not a "time", so far, in practice.
>
>

Oh, but that's far weirder!  I would not have expected that to be legal.  So
"now" is a strange animal indeed, having traits of both time and duration...

Actually, it looks like any time type divided by a duration returns a
float.  hrm...  I wouldn't have guessed.


> A keyword for this may not be enough. The following is a attempt to create
> my own "birth" keyword expressing this. I can't get it smaller then this and
> I would say this is quite perverse in a way;
>
>  //strongly typed meets strongly timed :¬p
> //at least it runs and works....
> now - ((now /samp)::samp) => time birth;
>
> I'd say this means casting can make sense but I'm open to ideas.
>

I still don't like the idea that a time can be cast as a
duration-from-vm-start, however, a "birth" keyword makes sense.  Consider
this:

2::second => now;  // is kind of like "for the next two seconds" or "two
seconds from now", etc.

if we had some idiom for "since"...  like:

since(now, birth) => dur aliveTime;    // which you could build...

or:

2::second + birth => time twoSecAfterBirth;

You're right, that would make timing relative to the VM starting up much
simpler.

your way is clever:
 //strongly typed meets strongly timed :¬p
//at least it runs and works....
now - ((now /samp)::samp) => time birth;

But I feel like you shouldn't have to do that.  I see how you could easily
abstract this using functions, but a keyword for the time that the VM
started seems like it would be easier, more global, etc.

at least, this returns a -1:

now - ((now /samp)::samp) => time birth;
<<<(birth - 2::second) /2::second>>>;

I was worried...  :)

-mike


>
>
>
>
> Of course, you could just approximate this functionality by having this
> > line run the moment the vm starts:
> >
> > now => time vmstart;
> >
> > Then, you'd be able to the do everything relative to that time.  At
> > least, that's how I would solve it.
>
>
> Maybe you'll like my attempt above too.... well, I think it works....
>
> Kas.
>
>
>
> _______________________________________________
> chuck-users mailing list
> chuck-users at lists.cs.princeton.edu
> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
>
>


-- 
http://semiotech.org
http://blog.deadlylittlepills.com
http://www.murderkills.com
http://shadowofaculture.blogspot.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20080107/3f20b98e/attachment.htm 


More information about the chuck-users mailing list