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

📄 faq.html

📁 Scheme跨平台编译器
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<html><head><title>CHICKEN User's Manual - faq</title></head><body><p> </p><a name="faq"></a><h1>FAQ</h1><p>This is the list of Frequently Asked Questions about Chicken Scheme. If you have a question not answered here, feel free to post to the chicken-users mailing list; if you consider your question general enough, feel free to add it to this list.</p><a name="general"></a><h2>General</h2><a name="why-yet-another-scheme-implementation"></a><h3>Why yet another Scheme implementation?</h3><p>Since Scheme is a relatively simple language, a large number of implementations exist and each has its specific advantages and disadvantages. Some are fast, some provide a rich programming environment. Some are free, others are tailored to specific domains, and so on. The reasons for the existence of CHICKEN are:</p><ul><li>CHICKEN is portable because it generates C code that runs on a large number of platforms.</li><li>CHICKEN is extendable, since its code generation scheme and runtime system/garbage collector fits neatly into a C environment.</li><li>CHICKEN is free and can be freely distributed, including its source code.</li><li>CHICKEN offers better performance than nearly all interpreter based implementations, but still provides full Scheme semantics.</li><li>As far as we know, CHICKEN is the first implementation of Scheme that uses Henry Baker's <a href="http://home.pipeline.com/~hbaker1/CheneyMTA.html" class="external">Cheney on the M.T.A</a> concept.</li></ul><a name="why-call-it-chicken"></a><h3>Why call it 'Chicken'?</h3><p>According to <a href="http://chicken.wiki.br/felix winkelmann" class="external">felix</a>:</p><blockquote><p>Well, it's pretty boring, really: when I started the project and needed some name, the first thing that met my eyes was the "chicken" (actually a disguised penguin)  from the Wallace + Gromit movie... And then there is of course the ever occurring chicken-and-egg problem with bootstrapped compilers.</p></blockquote><a name="what-should-i-do-if-i-find-a-bug"></a><h3>What should I do if I find a bug?</h3><p>Send e-mail to <a href="mailto:felix@call-with-current-continuation.org" class="external">felix@call-with-current-continuation.org</a> with some hints about the problem, like version/build of the compiler, platform, system configuration, code that causes the bug, etc.</p><a name="why-are-values-defined-with-define-foreign-variable-or-define-constant-or-define-inline-not-seen-outside-of-the-containing-source-file"></a><h3>Why are values defined with <tt>define-foreign-variable</tt> or <tt>define-constant</tt> or <tt>define-inline</tt> not seen outside of the containing source file?</h3><p>Accesses to foreign variables are translated directly into C constructs that access the variable, so the Scheme name given to that variable does only exist during compile-time. The same goes for constant- and inline-definitions: The name is only there to tell the compiler that this reference is to be replaced with the actual value.</p><a name="how-does-cond-expand-know-which-features-are-registered-in-used-units"></a><h3>How does <tt>cond-expand</tt> know which features are registered in used units?</h3><p>Each unit used via <tt>(declare (uses ...))</tt> is registered as a feature and so a symbol with the unit-name can be tested by <tt>cond-expand</tt> during macro-expansion-time. Features registered using the <tt>register-feature!</tt> procedure are only available during run-time of the compiled file. You can use the <tt>eval-when</tt> form to register features at compile time.</p><a name="why-are-constants-defined-by-define-constant-not-honoured-in-case-constructs"></a><h3>Why are constants defined by <tt>define-constant</tt> not honoured in <tt>case</tt> constructs?</h3><p><tt>case</tt> expands into a cascaded <tt>if</tt> expression, where the first item in each arm is treated as a quoted list. So the <tt>case</tt> macro can not infer whether a symbol is to be treated as a constant-name (defined via <tt>define-constant</tt>) or a literal symbol.</p><a name="how-can-i-enable-case-sensitive-reading-writing-in-user-code"></a><h3>How can I enable case sensitive reading/writing in user code?</h3><p>To enable the <tt>read</tt> procedure to read symbols and identifiers case sensitive, you can set the parameter <tt>case-sensitivity</tt> to <tt>#t</tt>.</p><a name="how-can-i-change-match-error-control-during-compilation"></a><h3>How can I change <tt>match-error-control</tt> during compilation?</h3><p>Use <tt>eval-when</tt>, like this:</p><PRE>(eval-when (compile)(match-error-control #:unspecified) )</PRE><a name="why-doesn-t-chicken-support-the-full-numeric-tower-by-default"></a><h3>Why doesn't CHICKEN support the full numeric tower by default?</h3><p>The short answer:</p><PRE>% chicken-setup numbers% csi -q#<I><FONT COLOR="#B22222">;1&gt; (use numbers)</FONT></I></PRE><p>The long answer:</p><p>There are a number of reasons for this:</p><p>- For most applications of Scheme fixnums (exact word-sized integers) and flonums (64-bit floating-point numbers) are more than sufficient;</p><p>- Interfacing to C is simpler;</p><p>- Dispatching of arithmetic operations is more efficient.</p><p>There is an extension based on the GNU Multiprecision Package that implements most of the full numeric tower, see <a href="http://chicken.wiki.br/numbers" class="external">numbers</a>.</p><a name="how-can-i-specialize-a-generic-function-method-to-match-instances-of-every-class"></a><h3>How can I specialize a generic function method to match instances of every class?</h3><p>Specializing a method on <tt>&lt;object&gt;</tt> doesn't work on primitive data objects like numbers, strings, etc. so for example</p><PRE>(define-method (foo (x &lt;my-class&gt;)) ...)(define-method (foo (x &lt;object&gt;)) ...)(foo 123)</PRE><p>will signal an error, because to applicable method can be found. To specialize a method for primitive objects, use <tt>&lt;top&gt;</tt>:</p><PRE>(define-method (foo (x &lt;top&gt;)) ...)</PRE><a name="does-chicken-support-native-threads"></a><h3>Does CHICKEN support native threads?</h3><p>Native threads are not supported for two reasons. One, the runtime system is not reentrant.  Two, concurrency implemented properly would require mandatory locking of every object that could be potentially shared between two threads. The garbage-collection algorithm would then become much more complex and inefficient, since the location of every object has to be accessed via a thread synchronization protocol. Such a design would make native threads in Chicken essentially equivalent to Unix processes and shared memory.</p><p>For a different approach to concurrency, please see the <a href="http://www.call-with-current-continuation.org/eggs/3/mpi.html" class="external">mpi</a> egg.</p><a name="does-chicken-support-unicode-strings"></a><h3>Does CHICKEN support Unicode strings?</h3><p>Yes, as an extension.</p><p>By default all string and character functions operate bytewise, so that characters with an iteger value greater than 255 don't make much sense and multibyte UTF-8 characters are seen and manipulated as separate bytes, analogous to what a C program would see.</p><p>You can enable UTF-8 support by placing the following two lines at the beginning of your source file (or in your ~/.csirc for interactive sessions) before any other code, including other use directives:</p><PRE>(use iset syntax-case utf8)(import utf8)</PRE><p>This will replace all builtin string operators with UTF-8-aware versions, that will treat strings as sequences of multibyte UTF-8 characters, thus enabling you to represent and manipulate Unicode characters while remaining compatible with most C libraries and system interfaces.</p><p>Most eggs should work correctly in utf8 mode, including the regex extension, but you still have the option of working around incompatibilities of specific eggs by loading them before the (import utf8) directive. Keep in mind that some operations, such as string-length, are much more expensive in utf8 (multibyte) mode, and should be used with care. See the <a href="http://www.call-with-current-continuation.org/eggs/utf8.html" class="external">utf8 egg documentation</a> for details.</p><a name="why-do-i-get-an-error-invalid-syntax-using-match-and-syntax-case"></a><h3>Why do I get an "Error: invalid syntax: ..." using 'match' and 'syntax-case'?</h3><p>The built-in 'match' macro is incompatible with 'syntax-case'. Use the  <a href="http://www.call-with-current-continuation.org/eggs/matchable.html" class="external">matchable egg</a> instead.</p><a name="platform-specific"></a><h2>Platform specific</h2><a name="how-do-i-generate-a-dll-under-ms-windows-tm"></a><h3>How do I generate a DLL under MS Windows (tm) ?</h3><p>Use <tt>csc</tt> in combination with the <tt>-dll</tt> option:</p><p><tt>C:\&gt; csc foo.scm -dll</tt></p><a name="how-do-i-generate-a-gui-application-under-windows-tm"></a><h3>How do I generate a GUI application under Windows(tm)?</h3><p>Invoke <tt>csc</tt> with the <tt>-windows</tt> option. Or pass the <tt>-DC_WINDOWS_GUI</tt> option to the C compiler and link with the GUI version of the runtime system (that's <tt>libchicken-gui[-static].lib</tt>. The GUI runtime displays error messages in a message box and does some rudimentary command-line parsing.</p><a name="compiling-very-large-files-under-windows-with-the-microsoft-c-compiler-fails-with-a-message-indicating-insufficient-heap-space"></a><h3>Compiling very large files under Windows with the Microsoft C compiler fails with a message indicating insufficient heap space.</h3><p>It seems that the Microsoft C compiler can only handle files up to a certain size, and it doesn't utilize virtual memory as well as the GNU C compiler, for example. Try closing running applications. If that fails, try to break up the Scheme code into several library units.</p><a name="when-i-run-csi-inside-an-emacs-buffer-under-windows-nothing-happens"></a><h3>When I run <tt>csi</tt> inside an emacs buffer under Windows, nothing happens.</h3><p>Invoke <tt>csi</tt> with the <tt>-:c</tt> runtime option. Under Windows the interpreter thinks it is not running under control of a terminal and doesn't print the prompt and does not flush the output stream properly.</p><a name="i-load-compiled-code-dynamically-in-a-windows-gui-application-and-it-crashes"></a><h3>I load compiled code dynamically in a Windows GUI application and it crashes.</h3><p>Code compiled into a DLL to be loaded dynamically must be linked with the same runtime system as the loading application. That means that all dynamically loaded entities (including extensions built and installed with <tt>chicken-setup</tt>) must be compiled with the <tt>-windows</tt> <tt>csc</tt> option.</p><a name="on-windows-csc-exe-seems-to-be-doing-something-wrong"></a><h3>On Windows, <tt>csc.exe</tt> seems to be doing something wrong.</h3><p>The Windows development tools include a C# compiler with the same name. Either invoke <tt>csc.exe</tt> with a full pathname, or put the directory where you installed CHICKEN in front of the MS development tool path in the <tt>PATH</tt> environment variable.</p><a name="on-windows-source-and-or-output-filenames-with-embedded-whitespace-are-not-found"></a><h3>On Windows source and/or output filenames with embedded whitespace are not found.</h3><p>There is no current workaround. Do not use filenames with embedded whitespace for code. However, command names with embedded whitespace will work correctly.</p><a name="customization"></a><h2>Customization</h2><a name="how-do-i-run-custom-startup-code-before-the-runtime-system-is-invoked"></a><h3>How do I run custom startup code before the runtime-system is invoked?</h3><p>When you invoke the C compiler for your translated Scheme source program, add the C compiler option <tt>-DC_EMBEDDED</tt>, or pass <tt>-embedded</tt> to the <tt>csc</tt> driver program, so no entry-point function will be generated (<tt>main()</tt>). When your are finished with your startup processing, invoke:</p><PRE><B><FONT COLOR="#0000FF">CHICKEN_main</FONT></B>(argc, argv, C_toplevel);</PRE><p>where <tt>C_toplevel</tt> is the entry-point into the compiled Scheme code. You should add the following  declarations at the head of your code:</p><PRE>#<B><FONT COLOR="#5F9EA0">include</FONT></B> <B><FONT COLOR="#BC8F8F">&quot;chicken.h&quot;</FONT></B><B><FONT COLOR="#228B22">extern</FONT></B> <B><FONT COLOR="#228B22">void</FONT></B> <B><FONT COLOR="#0000FF">C_toplevel</FONT></B>(C_word,C_word,C_word) C_noret;</PRE><a name="how-can-i-add-compiled-user-passes"></a><h3>How can I add compiled user passes?</h3><p>To add a compiled user pass instead of an interpreted one, create a library unit and recompile the main unit of the compiler (in the file <tt>chicken.scm</tt>) with an additional <tt>uses</tt> declaration. Then link all compiler modules and your (compiled) extension to create a new version of the compiler, like this (assuming all sources are in the current directory):</p><PRE>% cat userpass.scm<I><FONT COLOR="#B22222">;;;; userpass.scm - My very own compiler pass</FONT></I>(declare (unit userpass))<I><FONT COLOR="#B22222">;; Perhaps more user passes/extensions are added:</FONT></I>(<B><FONT COLOR="#A020F0">let</FONT></B> ([old (user-pass)])(user-pass(<B><FONT COLOR="#A020F0">lambda</FONT></B> (x)

⌨️ 快捷键说明

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