[chuck-users] Time logic

Martin Ahnelöv operagasten at gmail.com
Sun Nov 11 04:23:23 EST 2007


sön 2007-11-11 klockan 08:56 +0530 skrev AlgoMantra:
> "The fact that this expression evaluates to
> true after the waiting time is what confuses me, compared to
> traditional
> programing language control structures."
> 
> I've been following this thread and now I'm also very curious 
> to know the answer here. It's one thing to call for a delay
> in the main loop, but quite another to add a delay as condition. 
> 
> - fadereu
> 
> On Nov 11, 2007 7:34 AM, Juan-Pablo Caceres <
> jcaceres at ccrma.stanford.edu> wrote:
>         Martin Ahnelöv wrote:
>         > lör 2007-11-10 klockan 09:29 -0800 skrev Juan-Pablo Caceres:
>         >> Hi there,
>         >>
>         >> I have another question concerning time logic.  The
>         following 2 examples
>         >> are similar: 
>         >>
>         >> // 1)
>         >> while (true)
>         >> {
>         >>      <<<"HELLO">>>;
>         >>      1::second => now;
>         >> }
>         >>
>         >> // 2)
>         >> while (1::second => now) 
>         >> {
>         >>      <<<"HELLO">>>;
>         >> }
>         >>
>         >>
>         >> So the question is, is the second case using some syntactic
>         sugar?
>         >> Because conceptually it doesn't sound right to me. Maybe
>         the chuck gurus 
>         >> out there can make more sense of it?
>         >>
>         >
>         > Well, it's pretty easy, actually. While takes an expression,
>         and if that
>         > expression returns true, it evaluates the code inside the
>         brackets, and 
>         > then it tests the expression again. This expression can be
>         anything from
>         > "true", to "i<100", or even a function (that can do
>         absolutely
>         > anything). in the second case it's "1::second=>now", which
>         will return 
>         > true when 1 second have passed.
>         
>         
>         Hi Gastern,
>         
>         I understand how 'while' works on programming languages. What
>         confuses
>         me in chuck is the meaning of the expression
>         (dur => now)
>         
>         A 'while(expression)' cycle will stop executing the statement
>         as soon as
>         the expression evaluates to 'false'. In the case of evaluating
>         (dur =>
>         now), I think that there's also a timing logic involved, in
>         the sense 
>         that if (1::second => now) evaluates to 'true' only when 1
>         second has
>         passed, it should evaluate to false in every other time, which
>         would
>         cause the control to exit the block.
>         
>         What (I think) is going on is that (dur => now) as an
>         expression is just 
>         waiting, advancing time, and as soon as time has advances
>         'dur', it
>         evaluates to true by default. The fact that this expression
>         evaluates to
>         true after the waiting time is what confuses me, compared to
>         traditional 
>         programing language control structures.
>         


Well, the way I think of it is that the keyword now is just a function
or something, so passing dur to it is just like passing a float to Osc.freq.

Does that make things clearer?
Gasten





More information about the chuck-users mailing list