Oops. Here's the same patch, but inquiring about the correct file
descriptor.

(It'll work either way in some cases...)


On Thu, Aug 21, 2014 at 8:06 PM, David Lamkins <da...@lamkins.net> wrote:

> I've been puzzled by the interaction between GNU APL and aplwrap, in which
> ⎕ and ⍞ output doesn't appear until APL prompts for input. This behavior is
> bad for the case where the program tries to emit periodic progress messages
> during long computations.
>
> It turns out that the C++ std lib is responsible for this behavior. While
> cerr is unbuffered, cout holds onto buffered content for as long as
> possible. (Apparently it only does this when stdout is not a terminal, as
> running the same test in a shell window does not exhibit the aggressive
> buffering behavior.)
>
> I learned that cout's buffering behavior can be be changed using the call:
>
> std::cout.setf(std::ios::unitbuf);
>
> This can be called sometime before running the main APL loop, and will
> cause cout's buffer to be flushed at each <<, the same as cerr.
>
> The attached patch (GNU APL SVN 441) runs the 'unitbuf' code only in the
> case that stdin is not a tty.
>
>
>
> --
> "The secret to creativity is knowing how to hide your sources."
>    Albert Einstein
>
>
> http://soundcloud.com/davidlamkins
> http://reverbnation.com/lamkins
> http://reverbnation.com/lcw
> http://lamkins-guitar.com/
> http://lamkins.net/
> http://successful-lisp.com/
>



-- 
"The secret to creativity is knowing how to hide your sources."
   Albert Einstein


http://soundcloud.com/davidlamkins
http://reverbnation.com/lamkins
http://reverbnation.com/lcw
http://lamkins-guitar.com/
http://lamkins.net/
http://successful-lisp.com/
Index: src/Output.cc
===================================================================
--- src/Output.cc	(revision 441)
+++ src/Output.cc	(working copy)
@@ -170,6 +170,7 @@
       {
         use_curses = false;
       }
+   if (!isatty(fileno(stdout))) cout.setf(ios::unitbuf);
 }
 //-----------------------------------------------------------------------------
 int

Reply via email to