ideas for the "print" problem
Closed this issue · 2 comments
Currently, we have still the following situation in the GAE:
frege> print 42
res1 = ()
Could the following be a workaround:
Redirect the standard output to a StringBuffer before giving control to frege code with an IO x
type. Once it returns, print the StringBuffer along with the result.
(This will maybe look a bit unrealistic, as all output appears at once at the end, but hey ... better than no output at all.)
We may not want to redirect the standard output since one instance on GAE could be serving multiple REPL sessions so we would end up seeing other session's output. With a similar approach, I am thinking of redefining these functions to act on StringBuffer/StringBuilder instead: traceStr, traceStrLn, printStr, printStrLn and then trace, traceLn, print, println.
All the following functions will now work on 'tryfrege' in GAE:
print
, println
, trace
, traceLn
, traceStr
, traceStrLn
, printStr
, printStrLn
Changes:
- 'frege-scripting' has been modified to support multiple scripts just like in a scripting environment so that the definitions can be split into multiple files and imported.
- There is a new scripting file 'PreludeScripting.fr' in 'tryfrege' which has the modified definitions for the above functions to operate on
StringWriter
instead of system output and error stream. This file will be imported by default for every submission in online REPL. Since this is just an imported file in the current script, it wouldn't pollute current script namespace. So:l
will just list the identifiers entered in the REPL. This script will initializestdout
andstderr
on every script submission so that the lines written to stdout/stderr in previous submissions will not appear in successive submissions. - In 'tryfrege' REPL output, if
stdout
andstderr
are non-empty, then the contents of those will be printed, firststdout
thenstderr
followed by the actual output.