Jump to page: 1 2
Thread overview
Delay function?
Sep 02, 2008
Brendan
Sep 02, 2008
Brendan
Sep 02, 2008
Brendan
Sep 02, 2008
Chris R. Miller
Sep 02, 2008
Brendan
Sep 02, 2008
BCS
Sep 02, 2008
Brendan
Sep 03, 2008
BCS
Sep 03, 2008
Brendan
Sep 02, 2008
Denis Koroskin
Sep 02, 2008
Brendan
Sep 02, 2008
bearophile
Sep 02, 2008
BCS
September 02, 2008
I looked through the Phobos page, but haven't found anything like it. Is there a sort of delay function anywhere in Phobos?
September 02, 2008
Brendan Wrote:

> I looked through the Phobos page, but haven't found anything like it. Is there a sort of delay function anywhere in Phobos?

Well, I just used 'sleep' from the Linux shell instead. I don't understand yet what I'm doing wrong with the following function, though. Could someone explain and advise?


void scrollString( char[] s ) {
    for ( int i = 0; i < s.length; i++ )
      writef( s[i] );
      system( "sleep 0.2" );
  }

September 02, 2008
On Tue, Sep 2, 2008 at 7:11 AM, Brendan <brenzie@gmail.com> wrote:

> Brendan Wrote:
>
> > I looked through the Phobos page, but haven't found anything like it. Is
> there a sort of delay function anywhere in Phobos?
>
> Well, I just used 'sleep' from the Linux shell instead. I don't understand yet what I'm doing wrong with the following function, though. Could someone explain and advise?
>
>
> void scrollString( char[] s ) {
>    for ( int i = 0; i < s.length; i++ )
>      writef( s[i] );
>      system( "sleep 0.2" );
>  }
>
>
If you're expecting it to pause after each character.. you're missing braces around the body of the for loop, this isn't Python ;)


September 02, 2008
Reply to Brendan,

> Brendan Wrote:
> 
>> I looked through the Phobos page, but haven't found anything like it.
>> Is there a sort of delay function anywhere in Phobos?
>> 
> Well, I just used 'sleep' from the Linux shell instead. I don't
> understand yet what I'm doing wrong with the following function,
> though. Could someone explain and advise?
> 
> void scrollString( char[] s ) {
> for ( int i = 0; i < s.length; i++ )
> writef( s[i] );
> system( "sleep 0.2" );
> }

IIRC the are the standard sleep and usleep functions in std.c.something


September 02, 2008
Jarrett Billingsley Wrote:


> </blockquote></div><br>If you're expecting it to pause after each character.. you're missing braces around the body of the for loop, this isn't Python ;)<br></div>
> 

Oooooh, what a foolish mistake! How could I forget that? Thanks for pointing it out.

But the result isn't fruitful, though. When I run it, all I get is an empty screen, then after many seconds the whole string is displayed at once (not to mention I set the sleep time to 0.1 seconds). I'm probably missing something. Any idea?
September 02, 2008
Brendan wrote:
> Jarrett Billingsley Wrote:
> 
> 
>> </blockquote></div><br>If you're expecting it to pause after each character.. you're missing braces around the body of the for loop, this isn't Python ;)<br></div>
>>
> 
> Oooooh, what a foolish mistake! How could I forget that? Thanks for pointing it out.
> 
> But the result isn't fruitful, though. When I run it, all I get is an empty screen, then after many seconds the whole string is displayed at once (not to mention I set the sleep time to 0.1 seconds). I'm probably missing something. Any idea?

Flush the output?



September 02, 2008
On Tue, Sep 2, 2008 at 1:37 PM, Chris R. Miller < lordSaurontheGreat@gmail.com> wrote:

> Brendan wrote:
> > Jarrett Billingsley Wrote:
> >
> >
> >> </blockquote></div><br>If you're expecting it to pause after each
> character.. you're missing braces around the body of the for loop, this isn't Python ;)<br></div>
> >>
> >
> > Oooooh, what a foolish mistake! How could I forget that? Thanks for
> pointing it out.
> >
> > But the result isn't fruitful, though. When I run it, all I get is an
> empty screen, then after many seconds the whole string is displayed at once (not to mention I set the sleep time to 0.1 seconds). I'm probably missing something. Any idea?
>
> Flush the output?
>
>
Totally.

foreach(ch; s) { write(ch); fflush(stdout); system("pause 0.2"); }


September 02, 2008
Brendan:
> Oooooh, what a foolish mistake! How could I forget that? Thanks for pointing it out.

It's a mistake, but in the past years I have seen several similar mistakes in real programs written in C-like languages. That's why I'm a fan of semantically significant indentations :-) (Or of a built-in lint-like capability of the language that signals such indentation errors are syntax errors).

Bye,
bearophile
September 02, 2008
"bearophile" wrote
> Brendan:
>> Oooooh, what a foolish mistake! How could I forget that? Thanks for pointing it out.
>
> It's a mistake, but in the past years I have seen several similar mistakes in real programs written in C-like languages. That's why I'm a fan of semantically significant indentations :-) (Or of a built-in lint-like capability of the language that signals such indentation errors are syntax errors).

Any reasonable syntax highlighting editor should show you that you forgot something.

In vim, if I forget something like this, the second statement's indent jumps back to the same level as the if statement, signalling that I forgot to add the curly brace.

-Steve


September 02, 2008
Jarrett Billingsley Wrote:

> On Tue, Sep 2, 2008 at 1:37 PM, Chris R. Miller < lordSaurontheGreat@gmail.com> wrote:
> 
> > Brendan wrote:
> > > Jarrett Billingsley Wrote:
> > >
> > >
> > >> </blockquote></div><br>If you're expecting it to pause after each
> > character.. you're missing braces around the body of the for loop, this isn't Python ;)<br></div>
> > >>
> > >
> > > Oooooh, what a foolish mistake! How could I forget that? Thanks for
> > pointing it out.
> > >
> > > But the result isn't fruitful, though. When I run it, all I get is an
> > empty screen, then after many seconds the whole string is displayed at once (not to mention I set the sleep time to 0.1 seconds). I'm probably missing something. Any idea?
> >
> > Flush the output?
> >
> >
> Totally.
> 
> foreach(ch; s) { write(ch); fflush(stdout); system("pause 0.2"); }

Thanks! With a little quick tweaking it worked. But, even though I see the effective result, I don't entirely understand what it means "to flush" the output. I've never heard of this concept before and Google doesn't seem to return any useful answers. Could you explain?
« First   ‹ Prev
1 2