📄 faq.html
字号:
(<B><FONT COLOR="#A020F0">let</FONT></B> ([x2 (do-something-with x)]) (<B><FONT COLOR="#A020F0">if</FONT></B> old (old x2) x2) ) ) ) )</PRE><pre>% csc -c -x userpass.scm% csc chicken.scm -c -o chicken-extended.o -uses userpass% gcc chicken-extended.o support.o easyffi.o compiler.o optimizer.o batch-driver.o c-platform.o \c-backend.o userpass.o `csc -ldflags -libs` -o chicken-extended</pre><p>On platforms that support it (Linux ELF, Solaris, Windows + VC++), compiled code can be loaded via <tt>-extend</tt> just like source files (see <tt>load</tt> in the User's Manual).</p><a name="compiled-macros"></a><h2>Compiled macros</h2><a name="why-is-define-macro-complaining-about-unbound-variables"></a><h3>Why is <tt>define-macro</tt> complaining about unbound variables?</h3><p>Macro bodies that are defined and used in a compiled source-file are evaluated during compilation and so have no access to anything created with <tt>define</tt>. Use <tt>define-for-syntax</tt> instead.</p><a name="why-isn-t-load-properly-loading-my-library-of-macros"></a><h3>Why isn't <tt>load</tt> properly loading my library of macros?</h3><p>During compile-time, macros are only available in the source file in which they are defined. Files included via <tt>include</tt> are considered part of the containing file.</p><a name="why-is-include-unable-to-load-my-hygienic-macros"></a><h3>Why is <tt>include</tt> unable to load my hygienic macros?</h3><p>It is not sufficient for the included file to require the <tt>syntax-case</tt> extension. Call <tt>(require-extension syntax-case)</tt> <em>before</em> calling <tt>include</tt>.</p><a name="why-are-macros-not-visible-outside-of-the-compilation-unit-in-which-they-are-defined"></a><h3>Why are macros not visible outside of the compilation unit in which they are defined?</h3><p>Macros are defined during compile time, so when a file has been compiled, the definitions are gone. An exception to this rule are macros defined with <tt>define-macro</tt>, which are also visible at run-time, i.e. in <tt>eval</tt>. To use macros defined in other files, use the <tt>include</tt> special form.</p><a name="warnings-and-errors"></a><h2>Warnings and errors</h2><a name="why-does-my-program-crash-when-i-use-callback-functions-from-scheme-to-c-and-back-to-scheme-again"></a><h3>Why does my program crash when I use callback functions (from Scheme to C and back to Scheme again)?</h3><p>There are two reasons why code involving callbacks can crash out of no apparent reason:</p><ol><li>It is important to use <tt>foreign-safe-lambda/foreign-safe-lambda*</tt> for the C code that is to call back into Scheme. If this is not done than sooner or later the available stack space will be exhausted.</li><li>If the C code uses a large amount of stack storage, or if Scheme-to-C-to-Scheme calls are nested deeply, then the available nursery space on the stack will run low. To avoid this it might be advisable to run the compiled code with a larger nursery setting, i.e. run the code with <tt>-:s...</tt> and a larger value than the default (for example <tt>-:s300k</tt>), or use the <tt>-nursery</tt> compiler option. Note that this can decrease runtime performance on some platforms.</li></ol><a name="why-does-the-linker-complain-about-a-missing-function-c-toplevel"></a><h3>Why does the linker complain about a missing function <tt>_C_..._toplevel</tt>?</h3><p>This message indicates that your program uses a library-unit, but that the object-file or library was not supplied to the linker. If you have the unit <tt>foo</tt>, which is contained in <tt>foo.o</tt> than you have to supply it to the linker like this (assuming a GCC environment):</p><p><tt>% csc program.scm foo.o -o program</tt></p><a name="why-does-the-linker-complain-about-a-missing-function-c-toplevel"></a><h3>Why does the linker complain about a missing function <tt>_C_toplevel</tt>?</h3><p>This means you have compiled a library unit as an application. When a unit-declaration (as in <tt>(declare (unit ...))</tt>) is given, then this file has a specially named toplevel entry procedure. Just remove the declaration, or compile this file to an object-module and link it to your application code.</p><a name="why-does-my-program-crash-when-i-compile-a-file-with-unsafe-or-unsafe-declarations"></a><h3>Why does my program crash when I compile a file with <tt>-unsafe</tt> or unsafe declarations?</h3><p>The compiler option <tt>-unsafe</tt> or the declaration <tt>(declare (unsafe))</tt> disable certain safety-checks to improve performance, so code that would normally trigger an error will work unexpectedly or even crash the running application. It is advisable to develop and debug a program in safe mode (without unsafe declarations) and use this feature only if the application works properly.</p><a name="why-do-i-get-a-warning-when-i-define-a-global-variable-named-match"></a><h3>Why do I get a warning when I define a global variable named <tt>match</tt>?</h3><p>Even when the <tt>match</tt> unit is not used, the macros from that package are visible in the compiler. The reason for this is that macros can not be accessed from library units (only when explicitly evaluated in running code). To speed up macro-expansion time, the compiler and the interpreter both already provide the compiled <tt>match-...</tt> macro definitions. Macros shadowed lexically are no problem, but global definitions of variables named identically to (global) macros are useless - the macro definition shadows the global variable.</p><p>This problem can be solved using a different name or undefining the macro, like this:</p><PRE>(eval-when (compile eval) (undefine-macro! 'match))</PRE><a name="why-don-t-toplevel-continuations-captured-in-interpreted-code-work"></a><h3>Why don't toplevel-continuations captured in interpreted code work?</h3><p>Consider the following piece of code:</p><PRE> (<B><FONT COLOR="#A020F0">define</FONT></B> <B><FONT COLOR="#0000FF">k</FONT></B> (call-with-current-continuation (<B><FONT COLOR="#A020F0">lambda</FONT></B> (k) k)))(k k)</PRE><p>When compiled, this will loop endlessly. But when interpreted, <tt>(k k)</tt> will return to the read-eval-print loop! This happens because the continuation captured will eventually read the next toplevel expression from the standard-input (or an input-file if loading from a file). At the moment <tt>k</tt> was defined, the next expression was <tt>(k k)</tt>. But when <tt>k</tt> is invoked, the next expression will be whatever follows after <tt>(k k)</tt>. In other words, invoking a captured continuation will not rewind the file-position of the input source. A solution is to wrap the whole code into a <tt>(begin ...)</tt> expression, so all toplevel expressions will be loaded together.</p><a name="why-does-define-reader-ctor-not-work-in-my-compiled-program"></a><h3>Why does <tt>define-reader-ctor</tt> not work in my compiled program?</h3><p>The following piece of code does not work as expected:</p><PRE>(eval-when (compile)(define-reader-ctor 'integer->char integer->char) )(print #,(integer->char 33))</PRE><p>The problem is that the compiler reads the complete source-file before doing any processing on it, so the sharp-comma form is encountered before the reader-ctor is defined. A possible solution is to include the file containing the sharp-comma form, like this:</p><PRE>(eval-when (compile)(define-reader-ctor 'integer->char integer->char) )(include <B><FONT COLOR="#BC8F8F">"other-file"</FONT></B>)</PRE><PRE><I><FONT COLOR="#B22222">;;; other-file.scm:</FONT></I>(print #,(integer->char 33))</PRE><a name="why-do-built-in-units-such-as-srfi-1-srfi-18-and-posix-fail-to-load"></a><h3>Why do built-in units, such as srfi-1, srfi-18, and posix fail to load?</h3><p>When you try to <tt>use</tt> a built-in unit such as <tt>srfi-18</tt>, you may get the following error:</p><PRE>#<I><FONT COLOR="#B22222">;1> (use srfi-18)</FONT></I><I><FONT COLOR="#B22222">; loading library srfi-18 ...</FONT></I>Error: (load-library) unable to load librarysrfi-18<B><FONT COLOR="#BC8F8F">"dlopen(libchicken.dylib, 9): image not found"</FONT></B> <I><FONT COLOR="#B22222">;; on a Mac</FONT></I><B><FONT COLOR="#BC8F8F">"libchicken.so: cannot open shared object file: No such file or directory"</FONT></B> <I><FONT COLOR="#B22222">;; Linux</FONT></I></PRE>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -