digitalmars.D.learn - Delay function?
- Brendan <brenzie gmail.com> Sep 02 2008
- Brendan <brenzie gmail.com> Sep 02 2008
- "Jarrett Billingsley" <jarrett.billingsley gmail.com> Sep 02 2008
- Brendan <brenzie gmail.com> Sep 02 2008
- "Chris R. Miller" <lordSaurontheGreat gmail.com> Sep 02 2008
- Brendan <brenzie gmail.com> Sep 02 2008
- BCS <ao pathlink.com> Sep 02 2008
- Brendan <brenzie gmail.com> Sep 02 2008
- BCS <ao pathlink.com> Sep 02 2008
- Brendan <brenzie gmail.com> Sep 03 2008
- Brendan <brenzie gmail.com> Sep 02 2008
- bearophile <bearophileHUGS lycos.com> Sep 02 2008
- "Steven Schveighoffer" <schveiguy yahoo.com> Sep 02 2008
- BCS <ao pathlink.com> Sep 02 2008
- "Jarrett Billingsley" <jarrett.billingsley gmail.com> Sep 02 2008
- "Denis Koroskin" <2korden gmail.com> Sep 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?
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-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline 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
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" ); }
around the body of the for loop, this isn't Python ;)
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
Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Brendan wrote:Jarrett Billingsley Wrote: =20 =20</blockquote></div><br>If you're expecting it to pause after each char=
Python ;)<br></div>
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=
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
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
isn't Python ;)<br></div>
Oooooh, what a foolish mistake! How could I forget that? Thanks for
But the result isn't fruitful, though. When I run it, all I get is an
(not to mention I set the sleep time to 0.1 seconds). I'm probably missing something. Any idea? Flush the output?
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?
Sep 02 2008
Reply to Brendan,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
this isn't Python ;)<br></div>Oooooh, what a foolish mistake! How could I forget that? Thanks for
But the result isn't fruitful, though. When I run it, all I get is an
at once (not to mention I set the sleep time to 0.1 seconds). I'm probably missing something. Any idea? Flush the output?
foreach(ch; s) { write(ch); fflush(stdout); system("pause 0.2"); }
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?
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.
Sep 02 2008
BCS Wrote:Reply to Brendan,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
this isn't Python ;)<br></div>Oooooh, what a foolish mistake! How could I forget that? Thanks for
But the result isn't fruitful, though. When I run it, all I get is an
at once (not to mention I set the sleep time to 0.1 seconds). I'm probably missing something. Any idea? Flush the output?
foreach(ch; s) { write(ch); fflush(stdout); system("pause 0.2"); }
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?
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.
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?
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,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
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: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
Sep 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?
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
Sep 02 2008
Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline 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
isn't Python ;)<br></div>
Oooooh, what a foolish mistake! How could I forget that? Thanks for
But the result isn't fruitful, though. When I run it, all I get is an
(not to mention I set the sleep time to 0.1 seconds). I'm probably missing something. Any idea? Flush the output?
foreach(ch; s) { write(ch); fflush(stdout); system("pause 0.2"); }
Sep 02 2008
On Wed, 03 Sep 2008 00:24:02 +0400, Brendan <brenzie gmail.com> wrote: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
isn't Python ;)<br></div>
Oooooh, what a foolish mistake! How could I forget that? Thanks for
But the result isn't fruitful, though. When I run it, all I get is
empty screen, then after many seconds the whole string is displayed
(not to mention I set the sleep time to 0.1 seconds). I'm probably
something. Any idea? Flush the output?
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?
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; } }
Sep 02 2008









Brendan <brenzie gmail.com> 