Thread overview | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
September 02, 2008 Delay function? | ||||
---|---|---|---|---|
| ||||
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 Re: Delay function? | ||||
---|---|---|---|---|
| ||||
Posted in 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" );
}
|
September 02, 2008 Re: Delay function? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Brendan Attachments:
| 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 Re: Delay function? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Brendan | 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 Re: Delay function? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | 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 Re: Delay function? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Brendan Attachments:
| 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 Re: Delay function? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chris R. Miller Attachments:
| 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 Re: Delay function? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Brendan | 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 Re: Delay function? | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | "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 Re: Delay function? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | 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?
|
Copyright © 1999-2021 by the D Language Foundation