.toString() method works on objects only.  printing time and duration is always a little more work.<br><br>fun void printTime(time t)<br>{<br>    <<< t/second, "::second" >>>;<br>}<br><br>printTime(now);<br>
<br>or for durations, you can do the same kind of thing:<br><br>fun void printTime(dur t)<br>{<br>    <<< t/second, "::second" >>>;<br>}<br><br>printTime(400::ms);<br><br>this is generally what i do when i need to know print this kind of information.<br>
<br>-mike<br><br><br><div class="gmail_quote">On Sat, Jan 9, 2010 at 11:01 PM, Andrew Turley <span dir="ltr"><<a href="mailto:aturley@acm.org">aturley@acm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Sorry, yeah, the short answer is that there doesn't seem to be a good<br>
way to do what you're trying to do.<br>
<br>
If you want to see what Chuck does with "<<<" and ">>>", take a look<br>
at  Chuck_Instr_Hack::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )<br>
in chuck_instr.cpp for the details. There really isn't much in the way<br>
of conversion, it just uses fprintf to print a double.<br>
<br>
andy<br>
<div><div></div><div class="h5"><br>
On Sat, Jan 9, 2010 at 2:27 PM, Robert Poor <<a href="mailto:rdpoor@gmail.com">rdpoor@gmail.com</a>> wrote:<br>
> Andrew: Yep, I'd come up with the same thing: dedicated functions to<br>
> convert times and durations into strings.  That works fine, but my<br>
> question was actually simpler, and I apologize for not making it<br>
> clear.  What I should have said:<br>
><br>
> "It's clear that there are internal functions for converting times and<br>
> durations into strings, used in constructs such as:<br>
>  <<< now, 1::second >>>;<br>
> Are those internal functions available?"<br>
><br>
> ... and I'm guessing the answer is simply "no".  Your suggested<br>
> solution will do the job just fine (though I'd follow ChucK's lead and<br>
> print everything in terms of samples).  Thanks!<br>
><br>
> - Rob<br>
><br>
> On Sat, Jan 9, 2010 at 14:11, Andrew Turley <<a href="mailto:aturley@acm.org">aturley@acm.org</a>> wrote:<br>
>> So are you looking for something like this?<br>
>><br>
>> fun void log(string s) {<br>
>>  <<<s>>>;<br>
>> }<br>
>><br>
>> fun string stringify(dur d) {<br>
>>  return "" + ((d / (1::second))) + " seconds";<br>
>> }<br>
>><br>
>> fun string stringify(time t) {<br>
>>  return "" + ((t / (1::second))) + " seconds";<br>
>> }<br>
>><br>
>> 1::second => dur d1;<br>
>> log("d1 is " + stringify(d1)); // "d1 is 1 seconds"<br>
>> 300::samp => dur d2;<br>
>> log("d2 is " + stringify(d2)); // "d2 is 0.0068 seconds"<br>
>><br>
>> now + 60::second => time t1;<br>
>> log("t1 is " + stringify(t1)); // "t1 is 60 seconds"<br>
>> now + 1::minute => time t2;<br>
>> log("t2 is " + stringify(t2)); // "t2 is 60 seconds"<br>
>><br>
>> Or are you trying to do something else?<br>
>><br>
>> Understand that times are represented as a delta of the number of<br>
>> samples since the VM (or maybe it's the shred) started executing.<br>
>> Again, the time itself doesn't carry any information about how it was<br>
>> created, so these two times would have the same representation if they<br>
>> were created at the same time:<br>
>><br>
>> now + 1::minute => time t1;<br>
>> now + 60::second => time t2;<br>
>><br>
>> And these two times have different representations since they are not<br>
>> created at the same time:<br>
>><br>
>> now + 1::minute => time t1;<br>
>> 5::second => now;<br>
>> now + 60::second => time t2;<br>
>><br>
>> andy<br>
>><br>
>> On Sat, Jan 9, 2010 at 1:16 PM, Robert Poor <<a href="mailto:rdpoor@gmail.com">rdpoor@gmail.com</a>> wrote:<br>
>>> Sure, can do, but this is only for debugging -- I'd welcome a means to<br>
>>> get the same effect as<br>
>>>  <<< "duration is", d >>>;<br>
>>> which obviously works, but not as a string.  Same comments apply for<br>
>>> stringifying a time value.<br>
>>><br>
>>> - Rob<br>
>>><br>
>>> On Sat, Jan 9, 2010 at 13:08, Andrew Turley <<a href="mailto:aturley@acm.org">aturley@acm.org</a>> wrote:<br>
>>>> Are you looking for a way to generate something that would ultimately<br>
>>>> generate a string that contains "1::second"? Because if that's the<br>
>>>> case, you probably can't do it. Durations ultimately get stored as<br>
>>>> floats that represent the number of samples in the duration. And they<br>
>>>> don't, as far as I know, retain any information about the units that<br>
>>>> were used when they were created. So 6::second and 0.1::minute will<br>
>>>> both be stored as the number of samples that are contained in a 6<br>
>>>> second interval.<br>
>>>><br>
>>>> Now, what you can do is convert the duration to a float by doing this:<br>
>>>><br>
>>>> 1::second => dur d;<br>
>>>> d / (1::samp) => float dSamp;<br>
>>>><br>
>>>> And then you could convert that float to a string. Now what you<br>
>>>> probably want is a duration in terms of time rather than samples, so<br>
>>>> you could also get the number of samples per second and divide dSamp<br>
>>>> by that number, and then store your duration as a string<br>
>>>> representation of a floating point number represented in terms of<br>
>>>> seconds (or maybe you want milliseconds).<br>
>>>><br>
>>>> andy<br>
>>>><br>
>>>> On Sat, Jan 9, 2010 at 12:50 PM, Robert Poor <<a href="mailto:rdpoor@gmail.com">rdpoor@gmail.com</a>> wrote:<br>
>>>>> How can I cast a duration into a string (e.g. for passing as a string<br>
>>>>> argument)?  Consider:<br>
>>>>><br>
>>>>> // =============<br>
>>>>> fun void log(string message) {<br>
>>>>>  // do something to log the message<br>
>>>>> }<br>
>>>>><br>
>>>>> 1::second => dur d;<br>
>>>>> log("the duration is " + d);  // fails with "cannot perform '+' on<br>
>>>>> object references"<br>
>>>>> log("the duration is " + d.toString()); // fails with "type 'dur' does<br>
>>>>> not have members"<br>
>>>>> // =============<br>
>>>>><br>
>>>>> Same question for time objects.<br>
>>>>><br>
>>>>> TIA.<br>
>>>>><br>
>>>>> - Rob<br>
>>>>> _______________________________________________<br>
>>>>> chuck-users mailing list<br>
>>>>> <a href="mailto:chuck-users@lists.cs.princeton.edu">chuck-users@lists.cs.princeton.edu</a><br>
>>>>> <a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" target="_blank">https://lists.cs.princeton.edu/mailman/listinfo/chuck-users</a><br>
>>>>><br>
>>>> _______________________________________________<br>
>>>> chuck-users mailing list<br>
>>>> <a href="mailto:chuck-users@lists.cs.princeton.edu">chuck-users@lists.cs.princeton.edu</a><br>
>>>> <a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" target="_blank">https://lists.cs.princeton.edu/mailman/listinfo/chuck-users</a><br>
>>>><br>
>>><br>
>><br>
> _______________________________________________<br>
> chuck-users mailing list<br>
> <a href="mailto:chuck-users@lists.cs.princeton.edu">chuck-users@lists.cs.princeton.edu</a><br>
> <a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" target="_blank">https://lists.cs.princeton.edu/mailman/listinfo/chuck-users</a><br>
><br>
_______________________________________________<br>
chuck-users mailing list<br>
<a href="mailto:chuck-users@lists.cs.princeton.edu">chuck-users@lists.cs.princeton.edu</a><br>
<a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" target="_blank">https://lists.cs.princeton.edu/mailman/listinfo/chuck-users</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><a href="http://michaelclemow.com">http://michaelclemow.com</a><br><a href="http://semiotech.org">http://semiotech.org</a><br><br>