[chuck-users] making a duration into a string?

Andrew Turley aturley at acm.org
Sat Jan 9 16:08:07 EST 2010

Are you looking for a way to generate something that would ultimately
generate a string that contains "1::second"? Because if that's the
case, you probably can't do it. Durations ultimately get stored as
floats that represent the number of samples in the duration. And they
don't, as far as I know, retain any information about the units that
were used when they were created. So 6::second and 0.1::minute will
both be stored as the number of samples that are contained in a 6
second interval.

Now, what you can do is convert the duration to a float by doing this:

1::second => dur d;
d / (1::samp) => float dSamp;

And then you could convert that float to a string. Now what you
probably want is a duration in terms of time rather than samples, so
you could also get the number of samples per second and divide dSamp
by that number, and then store your duration as a string
representation of a floating point number represented in terms of
seconds (or maybe you want milliseconds).


On Sat, Jan 9, 2010 at 12:50 PM, Robert Poor <rdpoor at gmail.com> wrote:
> How can I cast a duration into a string (e.g. for passing as a string
> argument)?  Consider:
> // =============
> fun void log(string message) {
>  // do something to log the message
> }
> 1::second => dur d;
> log("the duration is " + d);  // fails with "cannot perform '+' on
> object references"
> log("the duration is " + d.toString()); // fails with "type 'dur' does
> not have members"
> // =============
> Same question for time objects.
> TIA.
> - Rob
> _______________________________________________
> chuck-users mailing list
> chuck-users at lists.cs.princeton.edu
> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users

More information about the chuck-users mailing list