ripping out with-output-to; unused

This commit is contained in:
Danny Yoo 2011-08-29 16:42:08 -04:00
parent 726bee2974
commit 84c7d457cb
5 changed files with 59 additions and 17 deletions

View File

@ -272,6 +272,23 @@
installPrimitiveProcedure(
'current-error-port',
makeList(0, 1),
function (MACHINE) {
if (MACHINE.argcount === 1) {
MACHINE.params['currentErrorPort'] =
checkOutputPort(MACHINE, 'current-output-port', 0);
return VOID;
} else {
return MACHINE.params['currentOutputPort'];
}
});
installPrimitiveProcedure(

View File

@ -475,3 +475,41 @@ For example,
}
@section{Tips and Tricks}
@subsection{Hiding standard output or directing it to an element}
@declare-exporting/this-package[web-world]
For a web-world program, output written by normal side effects such as
@racket[printf] or @racket[display] is still written to the current
output port, whose default behavior appends to the end of
@tt{document.body}. You may want to either disable such printing or
direct the output to a particular element on the page. For such
purposes, use a combination of @racket[current-output-port] and
@racket[open-output-element].
For example, in
@codeblock|{
...
(current-output-port (open-output-element "stdout-div"))
...
(big-bang ...
(on-tick (lambda (world dom)
(printf "Tick!\n")
(add1 world)))
...)
}|
All subsequent I/O side effects after the call to
@racket[current-output-port] will be written out to the
@tt{stdout-div}, which can be easily styled with @tt{display: none} to
hide it from normal browser display.
@defproc[(open-output-element [id string]) output-port]{
Opens an output port that will be directed to write to the DOM element
whose id is @racket[id]. Note: writing to this port shouldn't fail,
even if the id does not currently exist on the page.
}

View File

@ -28,9 +28,8 @@
;; draw and update the view
to-draw
with-output-to
open-output-element
;; helper: open an element as an output port.
open-output-element
;; coerse to view
->view

View File

@ -1109,12 +1109,12 @@
DomElementOutputPort.prototype.writeDomNode = function (MACHINE, v) {
$("#" + this.id).append(v);
$(v).trigger({type : 'afterAttach'});
$('*', v).trigger({type : 'afterAttach'});
};
//////////////////////////////////////////////////////////////////////
var checkReal = plt.baselib.check.checkReal;
@ -1455,13 +1455,6 @@
onChange);
});
EXPORTS['with-output-to'] = makePrimitiveProcedure(
'with-output-to',
1,
function(MACHINE) {
var outputPort = checkOutputPort(MACHINE, 'with-output-to', 0);
return new WithOutputToHandler(outputPort);
});
EXPORTS['open-output-element'] = makePrimitiveProcedure(
'open-output-element',

View File

@ -21,7 +21,6 @@
view-hide
view-append-child
with-output-to
open-output-element)
@ -121,9 +120,5 @@
(error 'view-append "Please run in JavaScript context."))
(define (with-output-to output-port)
(error 'with-output-to "Please run in JavaScript context."))
(define (open-output-element id)
(error 'open-output-element "Please run in JavaScript context."))