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

📄 unit-lolevel.html

📁 Scheme跨平台编译器
💻 HTML
📖 第 1 页 / 共 2 页
字号:
  (<B><FONT COLOR="#A020F0">define</FONT></B> (<B><FONT COLOR="#0000FF">make-point</FONT></B> x y)    (make-record-instance 'point x y) )  (<B><FONT COLOR="#A020F0">define</FONT></B> (<B><FONT COLOR="#0000FF">point?</FONT></B> x)    (<B><FONT COLOR="#A020F0">and</FONT></B> (record-instance? x)         (eq? 'point (block-ref x 0)) ) )  (<B><FONT COLOR="#A020F0">define</FONT></B> (<B><FONT COLOR="#0000FF">point-x</FONT></B> p) (block-ref p 1))  (<B><FONT COLOR="#A020F0">define</FONT></B> (<B><FONT COLOR="#0000FF">point-x-set!</FONT></B> p x) (block-set! p 1 x))  (<B><FONT COLOR="#A020F0">define</FONT></B> (<B><FONT COLOR="#0000FF">point-y</FONT></B> p) (block-ref p 2))  (<B><FONT COLOR="#A020F0">define</FONT></B> (<B><FONT COLOR="#0000FF">point-y-set!</FONT></B> p y) (block-set! p 1 y)) )</PRE><a name="move-memory"></a><h3>move-memory!</h3><pre>[procedure] (move-memory! FROM TO [BYTES [FROM-OFFSET [TO-OFFSET]])</pre><p>Copies <tt>BYTES</tt> bytes of memory from <tt>FROM</tt> to <tt>TO</tt>. <tt>FROM</tt> and <tt>TO</tt> may be strings, primitive byte-vectors, SRFI-4 byte-vectors (see: @ref{Unit srfi-4}), memory mapped files, foreign pointers (as obtained from a call to <tt>foreign-lambda</tt>, for example) or locatives. if <tt>BYTES</tt> is not given and the size of the source or destination operand is known then the maximal number of bytes will be copied. Moving memory to the storage returned by locatives will cause havoc,  if the locative refers to containers of non-immediate data, like vectors or pairs.</p><p>The additional fourth and fifth argument specify starting offsets  (in bytes) for the source and destination arguments.</p><a name="number-of-bytes"></a><h3>number-of-bytes</h3><pre>[procedure] (number-of-bytes BLOCK)</pre><p>Returns the number of bytes that the object <tt>BLOCK</tt> contains. <tt>BLOCK</tt> may be any non-immediate value.</p><a name="number-of-slots"></a><h3>number-of-slots</h3><pre>[procedure] (number-of-slots BLOCK)</pre><p>Returns the number of slots that the object <tt>BLOCK</tt> contains. <tt>BLOCK</tt> may be a vector, record structure, pair or symbol.</p><a name="record-instance"></a><h3>record-instance?</h3><pre>[procedure] (record-instance? X)</pre><p>Returns <tt>#t</tt> if <tt>X</tt> is an instance of a record type. See also: <tt>make-record-instance</tt>.</p><a name="record-vector"></a><h3>record&rarr;vector</h3><pre>[procedure] (record-&gt;vector BLOCK)</pre><p>Returns a new vector with the type and the elements of the record <tt>BLOCK</tt>.</p><a name="procedure-call-and-variable-reference-hooks"></a><h2>Procedure-call- and variable reference hooks</h2><a name="set-invalid-procedure-call-handler"></a><h3>set-invalid-procedure-call-handler!</h3><pre>[procedure] (set-invalid-procedure-call-handler! PROC)</pre><p>Sets an internal hook that is invoked when a call to an object other than a procedure is executed at runtime. The procedure <tt>PROC</tt> will in that case be called with two arguments: the object being called and a list of the passed arguments.</p><PRE><I><FONT COLOR="#B22222">;;; Access sequence-elements as in ARC:</FONT></I>(set-invalid-procedure-call-handler!  (<B><FONT COLOR="#A020F0">lambda</FONT></B> (proc args)    (<B><FONT COLOR="#A020F0">cond</FONT></B> [(string? proc) (apply string-ref proc args)]          [(vector? proc) (apply vector-ref proc args)]          [<B><FONT COLOR="#A020F0">else</FONT></B> (error <B><FONT COLOR="#BC8F8F">&quot;call of non-procedure&quot;</FONT></B> proc)] ) ) )(<B><FONT COLOR="#BC8F8F">&quot;hello&quot;</FONT></B> 4)    =<B><FONT COLOR="#A020F0">=&gt;</FONT></B>  #\o</PRE><p>This facility does not work in code compiled with the <em>unsafe</em> setting.</p><a name="unbound-variable-value"></a><h3>unbound-variable-value</h3><pre>[procedure] (unbound-variable-value [X])</pre><p>Defines the value that is returned for unbound variables. Normally an error is signalled, use this procedure to override the check and return <tt>X</tt> instead. To set the default behavior (of signalling an error), call <tt>unbound-variable-value</tt> with no arguments.</p><p>This facility does not work in code compiled with the <em>unsafe</em> setting.</p><a name="magic"></a><h2>Magic</h2><a name="object-become"></a><h3>object-become!</h3><pre>[procedure] (object-become! ALIST)</pre><p>Changes the identity of the value of the car of each pair in <tt>ALIST</tt> to the value of the cdr. Both values may not be immediate (i.e. exact integers, characters, booleans or the empty list).</p><PRE>(<B><FONT COLOR="#A020F0">define</FONT></B> <B><FONT COLOR="#0000FF">x</FONT></B> <B><FONT COLOR="#BC8F8F">&quot;i used to be a string&quot;</FONT></B>)(<B><FONT COLOR="#A020F0">define</FONT></B> <B><FONT COLOR="#0000FF">y</FONT></B> '#(<B><FONT COLOR="#A020F0">and</FONT></B> now i am a vector))(object-become! (list (cons x y)))x                                    =<B><FONT COLOR="#A020F0">=&gt;</FONT></B> #(<B><FONT COLOR="#A020F0">and</FONT></B> now i am a vector)y                                    =<B><FONT COLOR="#A020F0">=&gt;</FONT></B> #(<B><FONT COLOR="#A020F0">and</FONT></B> now i am a vector)(eq? x y)                            =<B><FONT COLOR="#A020F0">=&gt;</FONT></B> #t</PRE><p>Note: this operation invokes a major garbage collection.</p><p>The effect of using <tt>object-become!</tt> on evicted data (see <tt>object-evict</tt>) is undefined.</p><a name="mutate-procedure"></a><h3>mutate-procedure</h3><pre>[procedure] (mutate-procedure OLD PROC)</pre><p>Replaces the procedure <tt>OLD</tt> with the result of calling the one-argument procedure <tt>PROC</tt>. <tt>PROC</tt> will receive a copy of <tt>OLD</tt> that will be identical in behaviour to the result of <tt>PROC</tt>:</p><PRE><I><FONT COLOR="#B22222">;;; Replace arbitrary procedure with tracing one:</FONT></I>(mutate-procedure my-proc   (<B><FONT COLOR="#A020F0">lambda</FONT></B> (new)     (<B><FONT COLOR="#A020F0">lambda</FONT></B> args      (printf <B><FONT COLOR="#BC8F8F">&quot;~s called with arguments: ~s~%&quot;</FONT></B> new args)      (apply new args) ) ) )</PRE><p>Previous: <a href="unit-tcp.html" class="internal">Unit tcp</a></p><p>Next: <a href="interface-to-external-functions-and-variables.html" class="internal">Interface to external functions and variables</a></p></body></html>

⌨️ 快捷键说明

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