⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit-ports.html

📁 Scheme跨平台编译器
💻 HTML
字号:
<html><head><title>CHICKEN User's Manual - Unit ports</title></head><body><p> </p><a name="unit-ports"></a><h1>Unit ports</h1><p>This unit contains various extended port definitions. This unit is used by default, unless the program is compiled with the <tt>-explicit-use</tt> option.</p><a name="input-output-port-extensions"></a><h2>Input/output port extensions</h2><a name="with-output-to-port"></a><h3>with-output-to-port</h3><pre>[procedure] (with-output-to-port PORT THUNK)</pre><p>Call procedure <tt>THUNK</tt> with the current output-port temporarily bound to <tt>PORT</tt>.</p><a name="make-input-port"></a><h3>make-input-port</h3><pre>[procedure] (make-input-port READ READY? CLOSE [PEEK])</pre><p>Returns a custom input port. Common operations on this port are handled by the given parameters, which should be procedures of no arguments. <tt>READ</tt> is called when the next character is to be read and should return a character or <tt>#!eof</tt>. <tt>READY?</tt> is called when <tt>char-ready?</tt> is called on this port and should return <tt>#t</tt> or <tt>#f</tt>.  <tt>CLOSE</tt> is called when the port is closed. <tt>PEEK</tt> is called when <tt>peek-char</tt> is called on this port and should return a character or <tt>#!eof</tt>. if the argument <tt>PEEK</tt> is not given, then <tt>READ</tt> is used instead and the created port object handles peeking automatically (by calling <tt>READ</tt> and buffering the character).</p><a name="make-output-port"></a><h3>make-output-port</h3><pre>[procedure] (make-output-port WRITE CLOSE [FLUSH])</pre><p>Returns a custom output port. Common operations on this port are handled by the given parameters, which should be procedures.  <tt>WRITE</tt> is called when output is sent to the port and receives a single argument, a string.  <tt>CLOSE</tt> is called when the port is closed and should be a procedure of no arguments. <tt>FLUSH</tt> (if provided) is called for flushing the output port.</p><a name="with-error-output-to-port"></a><h3>with-error-output-to-port</h3><pre>[procedure] (with-error-output-to-port PORT THUNK)</pre><p>Call procedure <tt>THUNK</tt> with the current error output-port temporarily bound to <tt>PORT</tt>.</p><a name="with-input-from-port"></a><h3>with-input-from-port</h3><pre>[procedure] (with-input-from-port PORT THUNK)</pre><p>Call procedure <tt>THUNK</tt> with the current input-port temporarily bound to <tt>PORT</tt>.</p><a name="string-port-extensions"></a><h2>String-port extensions</h2><a name="call-with-input-string"></a><h3>call-with-input-string</h3><pre>[procedure] (call-with-input-string STRING PROC)</pre><p>Calls the procedure <tt>PROC</tt> with a single argument that is a string-input-port with the contents of <tt>STRING</tt>.</p><a name="call-with-output-string"></a><h3>call-with-output-string</h3><pre>[procedure] (call-with-output-string PROC)</pre><p>Calls the procedure <tt>PROC</tt> with a single argument that is a string-output-port.  Returns the accumulated output-string.</p><a name="with-input-from-string"></a><h3>with-input-from-string</h3><pre>[procedure] (with-input-from-string STRING THUNK)</pre><p>Call procedure <tt>THUNK</tt> with the current input-port temporarily bound to an input-string-port with the contents of <tt>STRING</tt>.</p><a name="with-output-to-string"></a><h3>with-output-to-string</h3><pre>[procedure] (with-output-to-string THUNK)</pre><p>Call procedure <tt>THUNK</tt> with the current output-port temporarily bound to a string-output-port and return the accumulated output string.</p><a name="port-iterators"></a><h2>Port iterators</h2><a name="port-for-each"></a><h3>port-for-each</h3><pre>[procedure] (port-for-each FN THUNK)</pre><p>Apply <tt>FN</tt> to successive results of calling the zero argument procedure <tt>THUNK</tt> until it returns <tt>#!eof</tt>, discarding the results.</p><a name="port-map"></a><h3>port-map</h3><pre>[procedure] (port-map FN THUNK)</pre><p>Apply <tt>FN</tt> to successive results of calling the zero argument procedure <tt>THUNK</tt> until it returns <tt>#!eof</tt>, returning a list of the collected results.</p><a name="port-fold"></a><h3>port-fold</h3><pre>[procedure] (port-map FN ACC THUNK)</pre><p>Apply <tt>FN</tt> to successive results of calling the zero argument procedure <tt>THUNK</tt>, passing the <tt>ACC</tt> value as the second argument. The <tt>FN</tt> result becomes the new <tt>ACC</tt> value. When <tt>THUNK</tt> returns <tt>#!eof</tt>, the last <tt>FN</tt> result is returned.</p><a name="funky-ports"></a><h2>Funky ports</h2><a name="make-broadcast-port"></a><h3>make-broadcast-port</h3><pre>[procedure] (make-broadcast-port PORT ...)</pre><p>Returns a custom output port that emits everything written into it to the ports given as <tt>PORT ...</tt>. Closing the broadcast port does not close any of the argument ports.</p><a name="make-concatenated-port"></a><h3>make-concatenated-port</h3><pre>[procedure] (make-concatenated-port PORT1 PORT2 ...)</pre><p>Returns a custom input port that reads its input from <tt>PORT1</tt>, until it is empty, then from <tt>PORT2</tt> and so on. Closing the concatenated port does not close any of the argument ports.</p><p>Previous: <a href="unit-data-structures.html" class="internal">Unit data-structures</a></p><p>Next: <a href="unit-files.html" class="internal">Unit files</a></p></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -