digitalmars.D.learn - Delay function?
- Brendan (1/1) Sep 02 2008 I looked through the Phobos page, but haven't found anything like it. Is...
- Brendan (7/8) Sep 02 2008 Well, I just used 'sleep' from the Linux shell instead. I don't understa...
- Jarrett Billingsley (4/15) Sep 02 2008 If you're expecting it to pause after each character.. you're missing br...
- Brendan (3/5) Sep 02 2008 Oooooh, what a foolish mistake! How could I forget that? Thanks for poin...
- Chris R. Miller (8/17) Sep 02 2008 acter.. you're missing braces around the body of the for loop, this isn'...
- Jarrett Billingsley (5/22) Sep 02 2008 Content-Disposition: inline
- Brendan (2/28) Sep 02 2008 Thanks! With a little quick tweaking it worked. But, even though I see t...
- BCS (4/39) Sep 02 2008 The act of making the screen show text is rather costly in time, so gene...
- Brendan (2/45) Sep 02 2008 Thanks for your responses, BCS. This is the first time I'm kind of commu...
- Denis Koroskin (14/49) Sep 02 2008 Google for "buffering". When you print something, it doesn't get display...
- Brendan (3/18) Sep 02 2008 Ahhh, a buffer!
- bearophile (4/5) Sep 02 2008 It's a mistake, but in the past years I have seen several similar mistak...
- Steven Schveighoffer (7/15) Sep 02 2008 Any reasonable syntax highlighting editor should show you that you forgo...
- BCS (2/16) Sep 02 2008 IIRC the are the standard sleep and usleep functions in std.c.something
I looked through the Phobos page, but haven't found anything like it. Is there a sort of delay function anywhere in Phobos?
Sep 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" ); }
Sep 02 2008
Content-Disposition: inline On Tue, Sep 2, 2008 at 7:11 AM, Brendan <brenzie gmail.com> wrote:Brendan Wrote: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 ;)I looked through the Phobos page, but haven't found anything like it. Isthere 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" ); }
Sep 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?
Sep 02 2008
Brendan wrote:Jarrett Billingsley Wrote: =20 =20acter.. you're missing braces around the body of the for loop, this isn't= Python ;)<br></div></blockquote></div><br>If you're expecting it to pause after each char=nting it out.=20 Oooooh, what a foolish mistake! How could I forget that? Thanks for poi==20 But the result isn't fruitful, though. When I run it, all I get is an e=mpty screen, then after many seconds the whole string is displayed at onc= e (not to mention I set the sleep time to 0.1 seconds). I'm probably miss= ing something. Any idea? Flush the output?
Sep 02 2008
Content-Disposition: inline On Tue, Sep 2, 2008 at 1:37 PM, Chris R. Miller < lordSaurontheGreat gmail.com> wrote:Brendan wrote:Totally. foreach(ch; s) { write(ch); fflush(stdout); system("pause 0.2"); }Jarrett Billingsley Wrote:character.. you're missing braces around the body of the for loop, this isn't Python ;)<br></div></blockquote></div><br>If you're expecting it to pause after eachpointing it out.Oooooh, what a foolish mistake! How could I forget that? Thanks forBut the result isn't fruitful, though. When I run it, all I get is anempty 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?
Sep 02 2008
Jarrett Billingsley Wrote:On Tue, Sep 2, 2008 at 1:37 PM, Chris R. Miller < lordSaurontheGreat gmail.com> wrote: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?Brendan wrote:Totally. foreach(ch; s) { write(ch); fflush(stdout); system("pause 0.2"); }Jarrett Billingsley Wrote:character.. you're missing braces around the body of the for loop, this isn't Python ;)<br></div></blockquote></div><br>If you're expecting it to pause after eachpointing it out.Oooooh, what a foolish mistake! How could I forget that? Thanks forBut the result isn't fruitful, though. When I run it, all I get is anempty 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?
Sep 02 2008
Reply to Brendan,Jarrett Billingsley Wrote:The act of making the screen show text is rather costly in time, so generally libs buffer your output, often until a newline or some preset amount. Flush just forces a buffer flush and the resultant output.On Tue, Sep 2, 2008 at 1:37 PM, Chris R. Miller < lordSaurontheGreat gmail.com> wrote: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?Brendan wrote:Totally. foreach(ch; s) { write(ch); fflush(stdout); system("pause 0.2"); }Jarrett Billingsley Wrote:character.. you're missing braces around the body of the for loop, this isn't Python ;)<br></div></blockquote></div><br>If you're expecting it to pause after eachOooooh, what a foolish mistake! How could I forget that? Thanks forpointing it out.But the result isn't fruitful, though. When I run it, all I get is anempty 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?
Sep 02 2008
BCS Wrote:Reply to Brendan,Thanks for your responses, BCS. This is the first time I'm kind of communicating through a newsgroup such as this, as I'm normally used to a forum. Why are your two messages separate from the thread?Jarrett Billingsley Wrote:The act of making the screen show text is rather costly in time, so generally libs buffer your output, often until a newline or some preset amount. Flush just forces a buffer flush and the resultant output.On Tue, Sep 2, 2008 at 1:37 PM, Chris R. Miller < lordSaurontheGreat gmail.com> wrote: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?Brendan wrote:Totally. foreach(ch; s) { write(ch); fflush(stdout); system("pause 0.2"); }Jarrett Billingsley Wrote:character.. you're missing braces around the body of the for loop, this isn't Python ;)<br></div></blockquote></div><br>If you're expecting it to pause after eachOooooh, what a foolish mistake! How could I forget that? Thanks forpointing it out.But the result isn't fruitful, though. When I run it, all I get is anempty 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?
Sep 02 2008
Reply to Brendan,Thanks for your responses, BCS. This is the first time I'm kind of communicating through a newsgroup such as this, as I'm normally used to a forum. Why are your two messages separate from the thread?If you are using the D web site interface, because it's broken (and has been for years). Best approach is to get a "real" newsgroup client program, thunderbird works, I use Omea by jetbrains and IIRC Outlook also does newsgroups.
Sep 02 2008
BCS wrote:Reply to Brendan,It's a lot better now, as I'm using Thunderbird. Thanks for the tip :)Thanks for your responses, BCS. This is the first time I'm kind of communicating through a newsgroup such as this, as I'm normally used to a forum. Why are your two messages separate from the thread?If you are using the D web site interface, because it's broken (and has been for years). Best approach is to get a "real" newsgroup client program, thunderbird works, I use Omea by jetbrains and IIRC Outlook also does newsgroups.
Sep 03 2008
On Wed, 03 Sep 2008 00:24:02 +0400, Brendan <brenzie gmail.com> wrote:Jarrett Billingsley Wrote:Google for "buffering". When you print something, it doesn't get displayed immediately. Instead, the string is copied to some internal buffer and when it gets full (or close to full) it is then flushed, i.e. its contents copied to the console and buffer size reset. Something like this: char[] buffer; void writefln(char[] str) { buffer ~= str; if (buffer.length > 1024) { doTheRealPrinting(buffer); buffer.length = 0; } }On Tue, Sep 2, 2008 at 1:37 PM, Chris R. Miller < lordSaurontheGreat gmail.com> wrote: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?Brendan wrote:thisJarrett Billingsley Wrote:character.. you're missing braces around the body of the for loop,</blockquote></div><br>If you're expecting it to pause after eachisn't Python ;)<br></div>anpointing it out.Oooooh, what a foolish mistake! How could I forget that? Thanks forBut the result isn't fruitful, though. When I run it, all I get isempty screen, then after many seconds the whole string is displayedat once(not to mention I set the sleep time to 0.1 seconds). I'm probablymissingsomething. Any idea? Flush the output?Totally. foreach(ch; s) { write(ch); fflush(stdout); system("pause 0.2"); }
Sep 02 2008
Denis Koroskin Wrote:Google for "buffering". When you print something, it doesn't get displayed immediately. Instead, the string is copied to some internal buffer and when it gets full (or close to full) it is then flushed, i.e. its contents copied to the console and buffer size reset. Something like this: char[] buffer; void writefln(char[] str) { buffer ~= str; if (buffer.length > 1024) { doTheRealPrinting(buffer); buffer.length = 0; } }Ahhh, a buffer! So basically, in the correct piece of code (the scroll function) a few messages back, in the for loop, the buffer is constantly unloading the characters from itself? It is so beautiful. Thanks :)
Sep 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
Sep 02 2008
"bearophile" wroteBrendan: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. -SteveOooooh, 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).
Sep 02 2008
Reply to Brendan,Brendan Wrote:IIRC the are the standard sleep and usleep functions in std.c.somethingI 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" ); }
Sep 02 2008